diff --git a/account_move_line_purchase_info/__manifest__.py b/account_move_line_purchase_info/__manifest__.py index 33e328d48..5025f0183 100644 --- a/account_move_line_purchase_info/__manifest__.py +++ b/account_move_line_purchase_info/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Account Move Line Purchase Info", "summary": "Introduces the purchase order line to the journal items", - "version": "12.0.1.0.1", + "version": "12.0.2.0.0", "author": "Eficent, " "Odoo Community Association (OCA)", "website": "https://www.github.com/OCA/account-financial-tools", diff --git a/account_move_line_purchase_info/migrations/12.0.2.0.0/pre-migration.py b/account_move_line_purchase_info/migrations/12.0.2.0.0/pre-migration.py new file mode 100644 index 000000000..77f8331cd --- /dev/null +++ b/account_move_line_purchase_info/migrations/12.0.2.0.0/pre-migration.py @@ -0,0 +1,38 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import logging + + +_logger = logging.getLogger(__name__) + +__name__ = "Upgrade to 12.0.2.0.0" + + +def update_purchase_id_column(cr): + cr.execute("""SELECT column_name + FROM information_schema.columns + WHERE table_name='account_move_line' AND + column_name='purchase_id'""") + if not cr.fetchone(): + _logger.info("""Add column purchase_id to account_move_line""") + cr.execute( + """ + ALTER TABLE account_move_line ADD COLUMN purchase_id integer; + """) + _logger.info("""Updating values for purchase_id in account_move_line""") + cr.execute( + """ + UPDATE account_move_line aml + SET purchase_id = pol.order_id + FROM purchase_order_line AS pol + WHERE aml.purchase_line_id = pol.id + """ + ) + + +def migrate(cr, version): + if not version: + return + update_purchase_id_column(cr) diff --git a/account_move_line_purchase_info/models/__init__.py b/account_move_line_purchase_info/models/__init__.py index 078b9f61f..eedcf9833 100644 --- a/account_move_line_purchase_info/models/__init__.py +++ b/account_move_line_purchase_info/models/__init__.py @@ -1,5 +1,5 @@ -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - from . import account_move from . import account_invoice +from . import purchase_order_line from . import stock_move + diff --git a/account_move_line_purchase_info/models/account_move.py b/account_move_line_purchase_info/models/account_move.py index ae13253b7..da1cfb616 100644 --- a/account_move_line_purchase_info/models/account_move.py +++ b/account_move_line_purchase_info/models/account_move.py @@ -14,3 +14,10 @@ class AccountMoveLine(models.Model): string='Purchase Order Line', ondelete='set null', index=True, ) + + purchase_id = fields.Many2one( + comodel_name='purchase.order', + related='purchase_line_id.order_id', + string='Purchase Order', + store=True, index=True, + ) diff --git a/account_move_line_purchase_info/models/purchase_order_line.py b/account_move_line_purchase_info/models/purchase_order_line.py new file mode 100644 index 000000000..6e6b5581c --- /dev/null +++ b/account_move_line_purchase_info/models/purchase_order_line.py @@ -0,0 +1,20 @@ +# Copyright 2019 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import api, models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + @api.multi + def name_get(self): + result = [] + orig_name = dict(super(PurchaseOrderLine, self).name_get()) + for line in self: + name = orig_name[line.id] + if self.env.context.get('po_line_info', False): + name = "[%s] %s (%s)" % (line.order_id.name, name, + line.order_id.state) + result.append((line.id, name)) + return result diff --git a/account_move_line_purchase_info/tests/test_account_move_line_purchase_info.py b/account_move_line_purchase_info/tests/test_account_move_line_purchase_info.py index 18b65f14a..c09df15b3 100644 --- a/account_move_line_purchase_info/tests/test_account_move_line_purchase_info.py +++ b/account_move_line_purchase_info/tests/test_account_move_line_purchase_info.py @@ -199,3 +199,14 @@ class TestAccountMoveLinePurchaseInfo(common.TransactionCase): self.assertEqual(aml.purchase_line_id, po_line, 'Purchase Order line has not been copied ' 'from the invoice to the account move line.') + + def test_name_get(self): + purchase = self._create_purchase([(self.product, 1)]) + po_line = purchase.order_line[0] + name_get = po_line.with_context({'po_line_info': True}).name_get() + self.assertEqual(name_get, [(po_line.id, "[%s] %s (%s)" % ( + po_line.order_id.name, po_line.name, + po_line.order_id.state, + ))]) + name_get_no_ctx = po_line.name_get() + self.assertEqual(name_get_no_ctx, [(po_line.id, po_line.name)]) diff --git a/account_move_line_purchase_info/views/account_move_view.xml b/account_move_line_purchase_info/views/account_move_view.xml index 49547e4fc..c5ab8bb13 100644 --- a/account_move_line_purchase_info/views/account_move_view.xml +++ b/account_move_line_purchase_info/views/account_move_view.xml @@ -7,6 +7,8 @@ + @@ -19,6 +21,8 @@ + @@ -31,9 +35,19 @@ + + groups="account_move_line_purchase_info.group_account_move_purchase_info"/> + + + + @@ -43,9 +57,10 @@ account.move - - + +