From be00c284c4d22599871e6b59a979948df388669a Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 8 Oct 2014 16:13:54 +0200 Subject: [PATCH] [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 lines --- base_transaction_id/__openerp__.py | 16 +++---- base_transaction_id/account_move.py | 4 +- .../account_move_line_view.xml | 15 ++++++ base_transaction_id/invoice.py | 42 ++++++++-------- base_transaction_id/invoice_view.xml | 48 +++++++++---------- base_transaction_id/sale.py | 25 ++++++---- base_transaction_id/sale_view.xml | 34 ++++++------- base_transaction_id/stock.py | 26 ++++------ 8 files changed, 104 insertions(+), 106 deletions(-) create mode 100644 base_transaction_id/account_move_line_view.xml diff --git a/base_transaction_id/__openerp__.py b/base_transaction_id/__openerp__.py index 9d1c1f5a..a4656d43 100644 --- a/base_transaction_id/__openerp__.py +++ b/base_transaction_id/__openerp__.py @@ -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': [], diff --git a/base_transaction_id/account_move.py b/base_transaction_id/account_move.py index dd64e529..2fd2e269 100644 --- a/base_transaction_id/account_move.py +++ b/base_transaction_id/account_move.py @@ -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) diff --git a/base_transaction_id/account_move_line_view.xml b/base_transaction_id/account_move_line_view.xml new file mode 100644 index 00000000..488968af --- /dev/null +++ b/base_transaction_id/account_move_line_view.xml @@ -0,0 +1,15 @@ + + + + + account.move.line.form + account.move.line + + + + + + + + + diff --git a/base_transaction_id/invoice.py b/base_transaction_id/invoice.py index 7460495c..f6fc40ee 100644 --- a/base_transaction_id/invoice.py +++ b/base_transaction_id/invoice.py @@ -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 diff --git a/base_transaction_id/invoice_view.xml b/base_transaction_id/invoice_view.xml index 2953720a..b96dc174 100644 --- a/base_transaction_id/invoice_view.xml +++ b/base_transaction_id/invoice_view.xml @@ -1,30 +1,26 @@ - - - customer.invoice.transaction.inherit - account.invoice - - form - - - - - - - - + + + customer.invoice.transaction.inherit + account.invoice + + + + + + + - - account.invoice.tree.inherit - account.invoice - - form - - - - - - - + + account.invoice.tree.inherit + account.invoice + + + + + + + + diff --git a/base_transaction_id/sale.py b/base_transaction_id/sale.py index 9e9fca3d..159414fb 100644 --- a/base_transaction_id/sale.py +++ b/base_transaction_id/sale.py @@ -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 diff --git a/base_transaction_id/sale_view.xml b/base_transaction_id/sale_view.xml index 512cac8c..d09f47a1 100644 --- a/base_transaction_id/sale_view.xml +++ b/base_transaction_id/sale_view.xml @@ -1,21 +1,15 @@ + - - - sale.order.form.transaction - sale.order - form - - - - - - - - - - \ No newline at end of file + + + sale.order.form.transaction + sale.order + + + + + + + + + diff --git a/base_transaction_id/stock.py b/base_transaction_id/stock.py index cd6d1e8b..840aedf1 100644 --- a/base_transaction_id/stock.py +++ b/base_transaction_id/stock.py @@ -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)