diff --git a/account_move_line_sale_info/README.rst b/account_move_line_sale_info/README.rst new file mode 100644 index 00000000..ffc69603 --- /dev/null +++ b/account_move_line_sale_info/README.rst @@ -0,0 +1,87 @@ +=========================== +Account Move Line Sale Info +=========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-tools/tree/15.0/account_move_line_sale_info + :alt: OCA/account-financial-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-tools-15-0/account-financial-tools-15-0-account_move_line_sale_info + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/92/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +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. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +The sale order line will be automatically copied to the journal items. + +* When a supplier 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. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow S.L. + +Contributors +~~~~~~~~~~~~ + +* Aaron Henriquez + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/account-financial-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_move_line_sale_info/__init__.py b/account_move_line_sale_info/__init__.py new file mode 100644 index 00000000..e66fb1c2 --- /dev/null +++ b/account_move_line_sale_info/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models +from .hooks import post_init_hook diff --git a/account_move_line_sale_info/__manifest__.py b/account_move_line_sale_info/__manifest__.py new file mode 100644 index 00000000..ae1989ac --- /dev/null +++ b/account_move_line_sale_info/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2020-23 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Account Move Line Sale Info", + "summary": "Introduces the purchase order line to the journal items", + "version": "16.0.1.0.0", + "author": "ForgeFlow S.L., " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-tools", + "category": "Generic", + "depends": [ + "account_move_line_stock_info", + "sale_stock", + ], + "license": "AGPL-3", + "data": ["security/account_security.xml", "views/account_move_view.xml"], + "installable": True, + "post_init_hook": "post_init_hook", +} diff --git a/account_move_line_sale_info/hooks.py b/account_move_line_sale_info/hooks.py new file mode 100644 index 00000000..2ccdb260 --- /dev/null +++ b/account_move_line_sale_info/hooks.py @@ -0,0 +1,70 @@ +# Copyright 2019-23 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +def post_init_hook(cr, registry): + + """INIT sale references in account move line""" + # FOR stock moves + cr.execute( + """ + UPDATE account_move_line aml SET sale_line_id = sm.sale_line_id + FROM account_move_line aml2 + INNER JOIN stock_move sm ON + aml2.stock_move_id = sm.id + WHERE aml.id = aml2.id; + """ + ) + # FOR invoices + cr.execute( + """ + UPDATE account_move_line aml SET sale_line_id = sol.id + FROM account_move_line aml2 + INNER JOIN account_move am ON + am.id = aml2.move_id + INNER JOIN sale_order_line_invoice_rel rel ON + rel.invoice_line_id = aml2.id + INNER JOIN sale_order_line sol ON + rel.order_line_id = sol.id + AND sol.product_id = aml2.product_id + WHERE aml.id = aml2.id; + """ + ) + + # NOW we can fill the SO + cr.execute( + """ + UPDATE account_move_line aml + SET sale_order_id = sol.order_id + FROM sale_order_line AS sol + WHERE aml.sale_line_id = sol.id + RETURNING aml.move_id + """ + ) + + # NOW we can fill the lines without invoice_id (Odoo put it very + # complicated) + + cr.execute( + """ + UPDATE account_move_line aml + SET sale_order_id = so.id + FROM sale_order so + LEFT JOIN account_move_line aml2 + ON aml2.sale_order_id = so.id + WHERE aml2.move_id = aml.move_id + """ + ) + + cr.execute( + """ + update account_move_line aml set sale_line_id = sol.id + FROM account_move_line aml2 + INNER JOIN sale_order so ON + so.id = aml2.sale_order_id + INNER JOIN sale_order_line sol ON + so.id = sol.order_id + AND sol.product_id = aml2.product_id + WHERE aml.id = aml2.id; + """ + ) diff --git a/account_move_line_sale_info/i18n/account_move_line_sale_info.pot b/account_move_line_sale_info/i18n/account_move_line_sale_info.pot new file mode 100644 index 00000000..3b759957 --- /dev/null +++ b/account_move_line_sale_info/i18n/account_move_line_sale_info.pot @@ -0,0 +1,55 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_line_sale_info +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_move_line_sale_info +#: model:ir.model,name:account_move_line_sale_info.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_move_line_sale_info +#: model:ir.model,name:account_move_line_sale_info.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_move_line_sale_info +#: model_terms:ir.ui.view,arch_db:account_move_line_sale_info.view_account_move_line_filter +msgid "Sale Order" +msgstr "" + +#. module: account_move_line_sale_info +#: model:ir.model.fields,field_description:account_move_line_sale_info.field_account_move_line__sale_line_id +#: model_terms:ir.ui.view,arch_db:account_move_line_sale_info.view_account_move_line_filter +msgid "Sale Order Line" +msgstr "" + +#. module: account_move_line_sale_info +#: model:res.groups,name:account_move_line_sale_info.group_account_move_sale_info +msgid "Sale info in Journal Items" +msgstr "" + +#. module: account_move_line_sale_info +#: model:ir.model.fields,field_description:account_move_line_sale_info.field_account_move_line__sale_order_id +msgid "Sales Order" +msgstr "" + +#. module: account_move_line_sale_info +#: model:ir.model,name:account_move_line_sale_info.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: account_move_line_sale_info +#: model:ir.model,name:account_move_line_sale_info.model_stock_move +msgid "Stock Move" +msgstr "" diff --git a/account_move_line_sale_info/i18n/es_AR.po b/account_move_line_sale_info/i18n/es_AR.po new file mode 100644 index 00000000..8be0dc26 --- /dev/null +++ b/account_move_line_sale_info/i18n/es_AR.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_line_sale_info +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-05-23 06:05+0000\n" +"Last-Translator: Ignacio Buioli \n" +"Language-Team: none\n" +"Language: es_AR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: account_move_line_sale_info +#: model:ir.model,name:account_move_line_sale_info.model_account_move +msgid "Journal Entry" +msgstr "Asiento Contable" + +#. module: account_move_line_sale_info +#: model:ir.model,name:account_move_line_sale_info.model_account_move_line +msgid "Journal Item" +msgstr "Apunte Contable" + +#. module: account_move_line_sale_info +#: model_terms:ir.ui.view,arch_db:account_move_line_sale_info.view_account_move_line_filter +msgid "Sale Order" +msgstr "Pedido de Venta" + +#. module: account_move_line_sale_info +#: model:ir.model.fields,field_description:account_move_line_sale_info.field_account_move_line__sale_line_id +#: model_terms:ir.ui.view,arch_db:account_move_line_sale_info.view_account_move_line_filter +msgid "Sale Order Line" +msgstr "Línea de Pedido de Venta" + +#. module: account_move_line_sale_info +#: model:res.groups,name:account_move_line_sale_info.group_account_move_sale_info +msgid "Sale info in Journal Items" +msgstr "Información de Venta de los Apuntes Contables" + +#. module: account_move_line_sale_info +#: model:ir.model.fields,field_description:account_move_line_sale_info.field_account_move_line__sale_order_id +msgid "Sales Order" +msgstr "Pedido de Venta" + +#. module: account_move_line_sale_info +#: model:ir.model,name:account_move_line_sale_info.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de Pedido de Venta" + +#. module: account_move_line_sale_info +#: model:ir.model,name:account_move_line_sale_info.model_stock_move +msgid "Stock Move" +msgstr "Movimiento de Inventario" diff --git a/account_move_line_sale_info/models/__init__.py b/account_move_line_sale_info/models/__init__.py new file mode 100644 index 00000000..c8dea955 --- /dev/null +++ b/account_move_line_sale_info/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import account_move +from . import sale_order_line +from . import stock_move diff --git a/account_move_line_sale_info/models/account_move.py b/account_move_line_sale_info/models/account_move.py new file mode 100644 index 00000000..5996b305 --- /dev/null +++ b/account_move_line_sale_info/models/account_move.py @@ -0,0 +1,49 @@ +# Copyright 2020-23 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + def _stock_account_prepare_anglo_saxon_out_lines_vals(self): + res = super()._stock_account_prepare_anglo_saxon_out_lines_vals() + 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"] + ).mapped("sale_line_ids") + if sale_line_id and len(sale_line_id) == 1: + res[i]["sale_line_id"] = sale_line_id.id + return res + + +class AccountMoveLine(models.Model): + + _inherit = "account.move.line" + + sale_line_id = fields.Many2one( + comodel_name="sale.order.line", + string="Sale Order Line", + ondelete="set null", + index=True, + copy=False, + ) + + sale_order_id = fields.Many2one( + comodel_name="sale.order", + related="sale_line_id.order_id", + string="Sales Order", + ondelete="set null", + store=True, + index=True, + copy=False, + ) + + 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) + 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 new file mode 100644 index 00000000..b6c8c109 --- /dev/null +++ b/account_move_line_sale_info/models/sale_order_line.py @@ -0,0 +1,25 @@ +# Copyright 2020-23 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import 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): + name = "[{}] {} - ({})".format( + line.order_id.name, line.product_id.name, line.order_id.state + ) + result.append((line.id, name)) + return result + + def _prepare_invoice_line(self, **optional_values): + res = super()._prepare_invoice_line(**optional_values) + res["sale_line_id"] = self.id + return res diff --git a/account_move_line_sale_info/models/stock_move.py b/account_move_line_sale_info/models/stock_move.py new file mode 100644 index 00000000..01627480 --- /dev/null +++ b/account_move_line_sale_info/models/stock_move.py @@ -0,0 +1,18 @@ +# Copyright 2020-23 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + @api.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( + qty, cost, credit_account_id, debit_account_id, svl_id, description + ) + for line in res: + line[2]["sale_line_id"] = self.sale_line_id.id + return res diff --git a/account_move_line_sale_info/readme/CONTRIBUTORS.rst b/account_move_line_sale_info/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..2e524967 --- /dev/null +++ b/account_move_line_sale_info/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Aaron Henriquez diff --git a/account_move_line_sale_info/readme/DESCRIPTION.rst b/account_move_line_sale_info/readme/DESCRIPTION.rst new file mode 100644 index 00000000..9d162406 --- /dev/null +++ b/account_move_line_sale_info/readme/DESCRIPTION.rst @@ -0,0 +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. diff --git a/account_move_line_sale_info/readme/USAGE.rst b/account_move_line_sale_info/readme/USAGE.rst new file mode 100644 index 00000000..d75919ab --- /dev/null +++ b/account_move_line_sale_info/readme/USAGE.rst @@ -0,0 +1,7 @@ +The sale order line will be automatically copied to the journal items. + +* When a supplier 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/security/account_security.xml b/account_move_line_sale_info/security/account_security.xml new file mode 100644 index 00000000..ab6f92cc --- /dev/null +++ b/account_move_line_sale_info/security/account_security.xml @@ -0,0 +1,8 @@ + + + + Sale info in Journal Items + + + + diff --git a/account_move_line_sale_info/static/description/icon.png b/account_move_line_sale_info/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/account_move_line_sale_info/static/description/icon.png differ diff --git a/account_move_line_sale_info/static/description/index.html b/account_move_line_sale_info/static/description/index.html new file mode 100644 index 00000000..5d2370c9 --- /dev/null +++ b/account_move_line_sale_info/static/description/index.html @@ -0,0 +1,432 @@ + + + + + + +Account Move Line Sale Info + + + +
+

Account Move Line Sale Info

+ + +

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

+

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.

+

Table of contents

+ +
+

Usage

+

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

+
    +
  • When a supplier 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.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow S.L.
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/account-financial-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_move_line_sale_info/tests/__init__.py b/account_move_line_sale_info/tests/__init__.py new file mode 100644 index 00000000..a2d0246f --- /dev/null +++ b/account_move_line_sale_info/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_account_move_line_sale_info 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 new file mode 100644 index 00000000..756880ac --- /dev/null +++ b/account_move_line_sale_info/tests/test_account_move_line_sale_info.py @@ -0,0 +1,272 @@ +# Copyright 2020-23 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo.tests import common + + +class TestAccountMoveLineSaleInfo(common.TransactionCase): + def setUp(self): + super(TestAccountMoveLineSaleInfo, self).setUp() + self.sale_model = self.env["sale.order"] + self.sale_line_model = self.env["sale.order.line"] + self.product_model = self.env["product.product"] + self.product_ctg_model = self.env["product.category"] + self.account_model = self.env["account.account"] + self.aml_model = self.env["account.move.line"] + self.res_users_model = self.env["res.users"] + + self.partner1 = self.env.ref("base.res_partner_1") + self.location_stock = self.env.ref("stock.stock_location_stock") + self.company = self.env.ref("base.main_company") + self.group_sale_user = self.env.ref("sales_team.group_sale_salesman") + self.group_account_invoice = self.env.ref("account.group_account_invoice") + self.group_account_manager = self.env.ref("account.group_account_manager") + + # Create account for Goods Received Not Invoiced + acc_type = "equity" + name = "Goods Received Not Invoiced" + code = "grni" + self.account_grni = self._create_account(acc_type, name, code, self.company) + + # Create account for Cost of Goods Sold + acc_type = "expense" + name = "Cost of Goods Sold" + code = "cogs" + self.account_cogs = self._create_account(acc_type, name, code, self.company) + # Create account for Inventory + acc_type = "asset_fixed" + name = "Inventory" + code = "inventory" + self.account_inventory = self._create_account( + acc_type, name, code, self.company + ) + # Create Product + self.product = self._create_product() + + # Create users + self.sale_user = self._create_user( + "sale_user", + [self.group_sale_user, self.group_account_invoice], + self.company, + ) + self.account_invoice = self._create_user( + "account_invoice", [self.group_account_invoice], self.company + ) + self.account_manager = self._create_user( + "account_manager", [self.group_account_manager], self.company + ) + self.JournalObj = self.env["account.journal"] + self.journal_sale = self.JournalObj.create( + { + "name": "Test journal sale", + "code": "TST-JRNL-S", + "type": "sale", + "company_id": self.company.id, + } + ) + + def _create_user(self, login, groups, company): + """Create a user.""" + group_ids = [group.id for group in groups] + user = self.res_users_model.with_context(**{"no_reset_password": True}).create( + { + "name": "Test User", + "login": login, + "password": "demo", + "email": "test@yourcompany.com", + "company_id": company.id, + "company_ids": [(4, company.id)], + "groups_id": [(6, 0, group_ids)], + } + ) + return user.id + + def _create_account(self, acc_type, name, code, company): + """Create an account.""" + account = self.account_model.create( + { + "name": name, + "code": code, + "account_type": acc_type, + "company_id": company.id, + } + ) + return account + + def _create_product(self): + """Create a Product.""" + # group_ids = [group.id for group in groups] + product_ctg = self.product_ctg_model.create( + { + "name": "test_product_ctg", + "property_stock_valuation_account_id": self.account_inventory.id, + "property_valuation": "real_time", + "property_stock_account_input_categ_id": self.account_grni.id, + "property_stock_account_output_categ_id": self.account_cogs.id, + } + ) + product = self.product_model.create( + { + "name": "test_product", + "categ_id": product_ctg.id, + "type": "product", + "standard_price": 1.0, + "list_price": 1.0, + } + ) + return product + + def _create_sale(self, line_products): + """Create a sale order. + + ``line_products`` is a list of tuple [(product, qty)] + """ + lines = [] + for product, qty in line_products: + line_values = { + "name": product.name, + "product_id": product.id, + "product_uom_qty": qty, + "product_uom": product.uom_id.id, + "price_unit": 500, + } + lines.append((0, 0, line_values)) + return self.sale_model.create( + {"partner_id": self.partner1.id, "order_line": lines} + ) + + def _get_balance(self, domain): + """ + Call read_group method and return the balance of particular account. + """ + aml_rec = self.aml_model.read_group( + domain, ["debit", "credit", "account_id"], ["account_id"] + ) + if aml_rec: + return aml_rec[0].get("debit", 0) - aml_rec[0].get("credit", 0) + else: + return 0.0 + + def _check_account_balance(self, account_id, sale_line=None, expected_balance=0.0): + """ + Check the balance of the account + """ + domain = [("account_id", "=", account_id)] + if sale_line: + domain.extend([("sale_line_id", "=", sale_line.id)]) + + balance = self._get_balance(domain) + if sale_line: + self.assertEqual( + balance, + expected_balance, + "Balance is not %s for sale Line %s." + % (str(expected_balance), sale_line.name), + ) + + def move_reversal_wiz(self, move): + wizard = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=[move.id]) + .create({"journal_id": move.journal_id.id}) + ) + return wizard + + def test_01_sale_invoice(self): + """Test that the po line moves from the sale order to the + account move line and to the invoice line. + """ + sale = self._create_sale([(self.product, 1)]) + so_line = False + for line in sale.order_line: + so_line = line + break + sale.action_confirm() + picking = sale.picking_ids[0] + picking.move_ids.write({"quantity_done": 1.0}) + picking.button_validate() + + expected_balance = -1.0 + self._check_account_balance( + self.account_inventory.id, + sale_line=so_line, + expected_balance=expected_balance, + ) + self.context = { + "active_model": "sale.order", + "active_ids": [sale.id], + "active_id": sale.id, + "default_journal_id": self.journal_sale.id, + } + payment = ( + self.env["sale.advance.payment.inv"] + .with_context(**self.context) + .create({"advance_payment_method": "delivered"}) + ) + payment.create_invoices() + invoice = sale.invoice_ids[0] + invoice._post() + + for aml in invoice.line_ids: + if aml.product_id == so_line.product_id and aml.move_id: + self.assertEqual( + aml.sale_line_id, + so_line, + "sale Order line has not been copied " + "from the invoice to the account move line.", + ) + + 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() + 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, + ), + ) + ], + ) + name_get_no_ctx = so_line.with_context(**{}).name_get() + self.assertEqual( + name_get_no_ctx, + [ + ( + so_line.id, + "{} - {}".format(so_line.order_id.name, so_line.product_id.name), + ) + ], + ) + + def test_03_credit_note(self): + """Test the credit note is linked to the sale order line""" + sale = self._create_sale([(self.product, 1)]) + so_line = False + for line in sale.order_line: + so_line = line + break + sale.action_confirm() + picking = sale.picking_ids[0] + picking.move_ids.write({"quantity_done": 1.0}) + picking.button_validate() + sale._create_invoices() + invoice = sale.invoice_ids[0] + invoice._post() + reversal_wizard = self.move_reversal_wiz(invoice) + credit_note = self.env["account.move"].browse( + reversal_wizard.reverse_moves()["res_id"] + ) + for aml in credit_note.line_ids: + if aml.product_id == so_line.product_id and aml.move_id: + self.assertEqual( + aml.sale_line_id, + so_line, + "sale Order line has not been copied " + "from the invoice to the credit note.", + ) diff --git a/account_move_line_sale_info/views/account_move_view.xml b/account_move_line_sale_info/views/account_move_view.xml new file mode 100644 index 00000000..93a24007 --- /dev/null +++ b/account_move_line_sale_info/views/account_move_view.xml @@ -0,0 +1,95 @@ + + + + account.move.line.form + account.move.line + + + + + + + + + + account.move.line.tree + account.move.line + + + + + + + + + + Journal Items + account.move.line + + + + + + + + + + + + + + account.move.form + account.move + + + + + + + + + diff --git a/setup/account_move_line_sale_info/odoo/addons/account_move_line_sale_info b/setup/account_move_line_sale_info/odoo/addons/account_move_line_sale_info new file mode 120000 index 00000000..2cd13006 --- /dev/null +++ b/setup/account_move_line_sale_info/odoo/addons/account_move_line_sale_info @@ -0,0 +1 @@ +../../../../account_move_line_sale_info \ No newline at end of file diff --git a/setup/account_move_line_sale_info/setup.py b/setup/account_move_line_sale_info/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_move_line_sale_info/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)