[MIG] base_transation_id: Fix migration to 8.0
- Use the 'data' key instead of 'update_xml' - Use the new api for account.invoice as the base model use it - The module now depends on 'sale_stock' and 'stock_account' - Avoid to write 2 times on the invoice by using the method that prepares the values before the write - Empty the transaction id of a sale order on copy - Some cleaning - Indent xml with 2 spaces - Cleaning of the views - Add the transaction ref field to the form view of the move linespull/524/head
parent
4fcd6366af
commit
26ac1f9401
|
@ -26,10 +26,9 @@
|
|||
'category': 'Hidden/Dependency',
|
||||
'complexity': 'easy',
|
||||
'depends': [
|
||||
'account',
|
||||
'sale',
|
||||
'stock'
|
||||
],
|
||||
'stock_account',
|
||||
'sale_stock',
|
||||
],
|
||||
'description': """
|
||||
Adds transaction id to invoice and sale models and views.
|
||||
On Sales order, you can specify the transaction ID used
|
||||
|
@ -43,12 +42,11 @@
|
|||
be able to find the partner when importing the bank statement.
|
||||
""",
|
||||
'website': 'http://www.openerp.com',
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
'data': [
|
||||
'invoice_view.xml',
|
||||
'sale_view.xml'
|
||||
],
|
||||
'demo_xml': [],
|
||||
'sale_view.xml',
|
||||
'account_move_line_view.xml',
|
||||
],
|
||||
'test': [],
|
||||
'installable': True,
|
||||
'images': [],
|
||||
|
|
|
@ -33,5 +33,5 @@ class account_move_line(orm.Model):
|
|||
if default is None:
|
||||
default = {}
|
||||
default['transaction_ref'] = False
|
||||
return super(account_move_line, self).\
|
||||
copy_data(cr, uid, id, default=default, context=context)
|
||||
_super = super(account_move_line, self)
|
||||
return _super.copy_data(cr, uid, id, default=default, context=context)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="0">
|
||||
<record id="view_move_line_form" model="ir.ui.view">
|
||||
<field name="name">account.move.line.form</field>
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="inherit_id" ref="account.view_move_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<group string="Reconciliation" position="inside">
|
||||
<field name="transaction_ref"/>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
|
@ -19,32 +19,30 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class AccountInvoice(Model):
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
_columns = {
|
||||
'transaction_id': fields.char(
|
||||
'Transaction id',
|
||||
select=1,
|
||||
help="Transaction id from the financial institute"),
|
||||
}
|
||||
transaction_id = fields.Char(string='Transaction ID',
|
||||
index=True,
|
||||
copy=False,
|
||||
help="Transaction ID from the "
|
||||
"financial institute")
|
||||
|
||||
def copy_data(self, cr, uid, id, default=None, context=None):
|
||||
if default is None:
|
||||
default = {}
|
||||
default['transaction_id'] = False
|
||||
return super(AccountInvoice, self).\
|
||||
copy_data(cr, uid, id, default=default, context=context)
|
||||
@api.multi
|
||||
def finalize_invoice_move_lines(self, move_lines):
|
||||
""" Propagate the transaction_id from the invoice to the move lines.
|
||||
|
||||
def finalize_invoice_move_lines(self, cr, uid, invoice_browse, move_lines):
|
||||
if invoice_browse.transaction_id:
|
||||
invoice_account_id = invoice_browse.account_id.id
|
||||
for line in move_lines:
|
||||
# tuple (0, 0, {values})
|
||||
if invoice_account_id == line[2]['account_id']:
|
||||
line[2]['transaction_ref'] = invoice_browse.transaction_id
|
||||
The transaction id is written on the move lines only if the account is
|
||||
the same than the invoice's one.
|
||||
"""
|
||||
for invoice in self:
|
||||
if invoice.transaction_id:
|
||||
invoice_account_id = invoice.account_id.id
|
||||
for line in move_lines:
|
||||
# line is a tuple (0, 0, {values})
|
||||
if invoice_account_id == line[2]['account_id']:
|
||||
line[2]['transaction_ref'] = invoice.transaction_id
|
||||
return move_lines
|
||||
|
|
|
@ -1,30 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="invoice_view_custom">
|
||||
<field name="name">customer.invoice.transaction.inherit</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_form"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<notebook position="inside">
|
||||
<page string="Transactions datas">
|
||||
<field name="transaction_id" select="2"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="invoice_view_custom">
|
||||
<field name="name">customer.invoice.transaction.inherit</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="origin" position="after">
|
||||
<field name="transaction_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="invoice_tree_custom">
|
||||
<field name="name">account.invoice.tree.inherit</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_tree"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="origin" position="after">
|
||||
<field name="transaction_id" select="2"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
<record model="ir.ui.view" id="invoice_tree_custom">
|
||||
<field name="name">account.invoice.tree.inherit</field>
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="origin" position="after">
|
||||
<field name="transaction_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -19,25 +19,30 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import fields
|
||||
from openerp.osv import orm, fields
|
||||
|
||||
|
||||
class SaleOrder(Model):
|
||||
class SaleOrder(orm.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
_columns = {
|
||||
'transaction_id': fields.char(
|
||||
'Transaction id',
|
||||
size=128,
|
||||
'Transaction ID',
|
||||
required=False,
|
||||
help="Transaction id from the financial institute"),
|
||||
}
|
||||
|
||||
def copy_data(self, cr, uid, id, default=None, context=None):
|
||||
if default is None:
|
||||
default = {}
|
||||
default['transaction_id'] = False
|
||||
_super = super(SaleOrder, self)
|
||||
return _super.copy_data(cr, uid, id, default=default, context=context)
|
||||
|
||||
def _prepare_invoice(self, cr, uid, order, lines, context=None):
|
||||
#we put the transaction id in the generated invoices
|
||||
invoice_vals = super(SaleOrder, self)._prepare_invoice(
|
||||
cr, uid, order, lines, context=context)
|
||||
invoice_vals.update({
|
||||
'transaction_id': order.transaction_id})
|
||||
""" Propagate the transaction_id from the sale order to the invoice """
|
||||
_super = super(SaleOrder, self)
|
||||
invoice_vals = _super._prepare_invoice(cr, uid, order, lines,
|
||||
context=context)
|
||||
invoice_vals['transaction_id'] = order.transaction_id
|
||||
return invoice_vals
|
||||
|
|
|
@ -1,21 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_order_form_transaction" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.transaction</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="payment_term" position="after">
|
||||
<field name="transaction_id" select="2"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<act_window
|
||||
domain="[('origin', '=', name)]"
|
||||
id="prm_act"
|
||||
name="Packing"
|
||||
res_model="stock.picking"
|
||||
src_model="sale.order"/>
|
||||
</data>
|
||||
</openerp>
|
||||
<data>
|
||||
<record id="view_order_form_transaction" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.transaction</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="payment_term" position="after">
|
||||
<field name="transaction_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -19,24 +19,16 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.osv import orm
|
||||
|
||||
|
||||
class StockPicking(Model):
|
||||
class StockPicking(orm.Model):
|
||||
_inherit = "stock.picking"
|
||||
|
||||
def action_invoice_create(
|
||||
self, cr, uid, ids, journal_id=False, group=False,
|
||||
type='out_invoice', context=None):
|
||||
res = super(StockPicking, self).action_invoice_create(
|
||||
cr, uid, ids, journal_id, group, type, context)
|
||||
for pick_id in res:
|
||||
pick = self.browse(cr, uid, pick_id, context=context)
|
||||
if pick.sale_id and pick.sale_id.transaction_id:
|
||||
self.pool.get('account.invoice').write(
|
||||
cr,
|
||||
uid,
|
||||
res[pick_id],
|
||||
{'transaction_id': pick.sale_id.transaction_id},
|
||||
context=context)
|
||||
return res
|
||||
def _create_invoice_from_picking(self, cr, uid, picking, vals,
|
||||
context=None):
|
||||
""" Propagate the transaction ID from sale to invoice """
|
||||
vals['transaction_id'] = picking.sale_id.transaction_id
|
||||
_super = super(StockPicking, self)
|
||||
return _super._create_invoice_from_picking(cr, uid, picking, vals,
|
||||
context=context)
|
||||
|
|
Loading…
Reference in New Issue