diff --git a/account_move_line_sale_info/README.rst b/account_move_line_sale_info/README.rst index 63a9c01c7..1ef9cd17a 100644 --- a/account_move_line_sale_info/README.rst +++ b/account_move_line_sale_info/README.rst @@ -30,9 +30,8 @@ Account Move Line Sale Info This module will add the sale order line to journal items. -The ultimate goal is to establish the purchase order line as one of the -key fields to reconcile the Goods Delivered Not Invoiced accrual -account. +The ultimate goal is to establish the sale order line as one of the key +fields to reconcile the Goods Delivered Not Invoiced accrual account. **Table of contents** @@ -44,7 +43,7 @@ Usage The sale order line will be automatically copied to the journal items. -- When a supplier invoice is created referencing sales orders, the sale +- When a customer invoice is created referencing sales orders, the sale order line will be copied to the corresponding journal item. - When a stock move is validated and generates a journal entry, the sale order line is copied to the account move line. @@ -71,6 +70,9 @@ Contributors ------------ - Aaron Henriquez +- `360ERP `__: + + - Andrea Stirpe Maintainers ----------- diff --git a/account_move_line_sale_info/__manifest__.py b/account_move_line_sale_info/__manifest__.py index ae1989ac0..e4232a645 100644 --- a/account_move_line_sale_info/__manifest__.py +++ b/account_move_line_sale_info/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account Move Line Sale Info", "summary": "Introduces the purchase order line to the journal items", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "author": "ForgeFlow S.L., " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", "category": "Generic", diff --git a/account_move_line_sale_info/hooks.py b/account_move_line_sale_info/hooks.py index 2ccdb260f..a6163315e 100644 --- a/account_move_line_sale_info/hooks.py +++ b/account_move_line_sale_info/hooks.py @@ -2,11 +2,10 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -def post_init_hook(cr, registry): - +def post_init_hook(env): """INIT sale references in account move line""" # FOR stock moves - cr.execute( + env.cr.execute( """ UPDATE account_move_line aml SET sale_line_id = sm.sale_line_id FROM account_move_line aml2 @@ -16,7 +15,7 @@ def post_init_hook(cr, registry): """ ) # FOR invoices - cr.execute( + env.cr.execute( """ UPDATE account_move_line aml SET sale_line_id = sol.id FROM account_move_line aml2 @@ -32,7 +31,7 @@ def post_init_hook(cr, registry): ) # NOW we can fill the SO - cr.execute( + env.cr.execute( """ UPDATE account_move_line aml SET sale_order_id = sol.order_id @@ -45,7 +44,7 @@ def post_init_hook(cr, registry): # NOW we can fill the lines without invoice_id (Odoo put it very # complicated) - cr.execute( + env.cr.execute( """ UPDATE account_move_line aml SET sale_order_id = so.id @@ -56,7 +55,7 @@ def post_init_hook(cr, registry): """ ) - cr.execute( + env.cr.execute( """ update account_move_line aml set sale_line_id = sol.id FROM account_move_line aml2 diff --git a/account_move_line_sale_info/models/account_move.py b/account_move_line_sale_info/models/account_move.py index 5996b3052..ee300fc33 100644 --- a/account_move_line_sale_info/models/account_move.py +++ b/account_move_line_sale_info/models/account_move.py @@ -12,8 +12,8 @@ class AccountMove(models.Model): for i, vals in enumerate(res): am = self.env["account.move"].browse(vals["move_id"]) sale_line_id = am.invoice_line_ids.filtered( - lambda il: il.product_id.id == vals["product_id"] - and il.quantity == vals["quantity"] + lambda il, vs=vals: il.product_id.id == vs["product_id"] + and il.quantity == vs["quantity"] ).mapped("sale_line_ids") if sale_line_id and len(sale_line_id) == 1: res[i]["sale_line_id"] = sale_line_id.id @@ -21,7 +21,6 @@ class AccountMove(models.Model): class AccountMoveLine(models.Model): - _inherit = "account.move.line" sale_line_id = fields.Many2one( @@ -44,6 +43,6 @@ class AccountMoveLine(models.Model): def _copy_data_extend_business_fields(self, values): # Same way Odoo standard does for purchase_line_id field - res = super(AccountMoveLine, self)._copy_data_extend_business_fields(values) + res = super()._copy_data_extend_business_fields(values) values["sale_line_id"] = self.sale_line_id.id return res diff --git a/account_move_line_sale_info/models/sale_order_line.py b/account_move_line_sale_info/models/sale_order_line.py index b6c8c109d..ea7ac9321 100644 --- a/account_move_line_sale_info/models/sale_order_line.py +++ b/account_move_line_sale_info/models/sale_order_line.py @@ -1,23 +1,23 @@ # Copyright 2020-23 ForgeFlow S.L. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import models +from odoo import api, models class SaleOrderLine(models.Model): _inherit = "sale.order.line" - def name_get(self): - result = [] - orig_name = dict(super(SaleOrderLine, self).name_get()) - for line in self: - name = orig_name[line.id] - if self.env.context.get("so_line_info", False): + @api.depends() + @api.depends_context("so_line_info") + def _compute_display_name(self): + res = super()._compute_display_name() + if self.env.context.get("so_line_info", False): + for line in self.sudo(): name = "[{}] {} - ({})".format( line.order_id.name, line.product_id.name, line.order_id.state ) - result.append((line.id, name)) - return result + line.display_name = name + return res def _prepare_invoice_line(self, **optional_values): res = super()._prepare_invoice_line(**optional_values) diff --git a/account_move_line_sale_info/models/stock_move.py b/account_move_line_sale_info/models/stock_move.py index 01627480f..d2f86cc3e 100644 --- a/account_move_line_sale_info/models/stock_move.py +++ b/account_move_line_sale_info/models/stock_move.py @@ -10,7 +10,7 @@ class StockMove(models.Model): def _prepare_account_move_line( self, qty, cost, credit_account_id, debit_account_id, svl_id, description ): - res = super(StockMove, self)._prepare_account_move_line( + res = super()._prepare_account_move_line( qty, cost, credit_account_id, debit_account_id, svl_id, description ) for line in res: diff --git a/account_move_line_sale_info/readme/CONTRIBUTORS.md b/account_move_line_sale_info/readme/CONTRIBUTORS.md index 5fd9ab677..d41140837 100644 --- a/account_move_line_sale_info/readme/CONTRIBUTORS.md +++ b/account_move_line_sale_info/readme/CONTRIBUTORS.md @@ -1 +1,3 @@ - Aaron Henriquez \<\> +- [360ERP](https://www.360erp.com): + - Andrea Stirpe diff --git a/account_move_line_sale_info/readme/DESCRIPTION.md b/account_move_line_sale_info/readme/DESCRIPTION.md index a6b16caf6..fdf14de95 100644 --- a/account_move_line_sale_info/readme/DESCRIPTION.md +++ b/account_move_line_sale_info/readme/DESCRIPTION.md @@ -1,5 +1,4 @@ This module will add the sale order line to journal items. -The ultimate goal is to establish the purchase order line as one of the -key fields to reconcile the Goods Delivered Not Invoiced accrual -account. +The ultimate goal is to establish the sale order line as one of the key +fields to reconcile the Goods Delivered Not Invoiced accrual account. diff --git a/account_move_line_sale_info/readme/USAGE.md b/account_move_line_sale_info/readme/USAGE.md index 509ece60d..fadba1822 100644 --- a/account_move_line_sale_info/readme/USAGE.md +++ b/account_move_line_sale_info/readme/USAGE.md @@ -1,6 +1,6 @@ The sale order line will be automatically copied to the journal items. -- When a supplier invoice is created referencing sales orders, the sale +- When a customer invoice is created referencing sales orders, the sale order line will be copied to the corresponding journal item. - When a stock move is validated and generates a journal entry, the sale order line is copied to the account move line. diff --git a/account_move_line_sale_info/static/description/index.html b/account_move_line_sale_info/static/description/index.html index b8597992d..b318d836f 100644 --- a/account_move_line_sale_info/static/description/index.html +++ b/account_move_line_sale_info/static/description/index.html @@ -371,9 +371,8 @@ ul.auto-toc { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runboat

This module will add the sale order line to journal items.

-

The ultimate goal is to establish the purchase order line as one of the -key fields to reconcile the Goods Delivered Not Invoiced accrual -account.

+

The ultimate goal is to establish the sale order line as one of the key +fields to reconcile the Goods Delivered Not Invoiced accrual account.

Table of contents

    @@ -391,7 +390,7 @@ account.

    Usage

    The sale order line will be automatically copied to the journal items.

      -
    • When a supplier invoice is created referencing sales orders, the sale +
    • When a customer invoice is created referencing sales orders, the sale order line will be copied to the corresponding journal item.
    • When a stock move is validated and generates a journal entry, the sale order line is copied to the account move line.
    • @@ -417,6 +416,10 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

      Contributors

diff --git a/account_move_line_sale_info/tests/test_account_move_line_sale_info.py b/account_move_line_sale_info/tests/test_account_move_line_sale_info.py index 756880ac0..fe7974bd5 100644 --- a/account_move_line_sale_info/tests/test_account_move_line_sale_info.py +++ b/account_move_line_sale_info/tests/test_account_move_line_sale_info.py @@ -5,7 +5,7 @@ from odoo.tests import common class TestAccountMoveLineSaleInfo(common.TransactionCase): def setUp(self): - super(TestAccountMoveLineSaleInfo, self).setUp() + super().setUp() self.sale_model = self.env["sale.order"] self.sale_line_model = self.env["sale.order.line"] self.product_model = self.env["product.product"] @@ -159,8 +159,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase): self.assertEqual( balance, expected_balance, - "Balance is not %s for sale Line %s." - % (str(expected_balance), sale_line.name), + f"Balance is not {str(expected_balance)} for sale Line {sale_line.name}.", ) def move_reversal_wiz(self, move): @@ -182,7 +181,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase): break sale.action_confirm() picking = sale.picking_ids[0] - picking.move_ids.write({"quantity_done": 1.0}) + picking.move_ids.write({"quantity": 1.0, "picked": True}) picking.button_validate() expected_balance = -1.0 @@ -218,30 +217,23 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase): def test_02_name_get(self): sale = self._create_sale([(self.product, 1)]) so_line = sale.order_line[0] - name_get = so_line.with_context(**{"so_line_info": True}).name_get() + name_get = so_line.with_context(**{"so_line_info": True}).display_name self.assertEqual( name_get, - [ - ( - so_line.id, - "[%s] %s - (%s)" - % ( - so_line.order_id.name, - so_line.product_id.name, - so_line.order_id.state, - ), - ) - ], + "[{}] {} - ({})".format( + so_line.order_id.name, + so_line.product_id.name, + so_line.order_id.state, + ), ) - name_get_no_ctx = so_line.with_context(**{}).name_get() + name_get_no_ctx = so_line.with_context(**{}).display_name self.assertEqual( name_get_no_ctx, - [ - ( - so_line.id, - "{} - {}".format(so_line.order_id.name, so_line.product_id.name), - ) - ], + "{} - {} {}".format( + so_line.order_id.name, + so_line.product_id.name, + so_line._additional_name_per_id()[so_line.id], + ), ) def test_03_credit_note(self): @@ -253,7 +245,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase): break sale.action_confirm() picking = sale.picking_ids[0] - picking.move_ids.write({"quantity_done": 1.0}) + picking.move_ids.write({"quantity": 1.0, "picked": True}) picking.button_validate() sale._create_invoices() invoice = sale.invoice_ids[0]