diff --git a/purchase_order_line_sequence/README.rst b/purchase_order_line_sequence/README.rst new file mode 100644 index 00000000000..6a88bf404da --- /dev/null +++ b/purchase_order_line_sequence/README.rst @@ -0,0 +1,93 @@ +============================ +Purchase Order Line Sequence +============================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/16.0/purchase_order_line_sequence + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-16-0/purchase-workflow-16-0-purchase_order_line_sequence + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/142/16.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + + +The sequence in PO line is propagated to the Stock moves. The sequence number +appears in the PO form view and in the report. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + + +This module depends on the following module(s) : + * stock_picking_line_sequence (https://github.com/OCA/stock-logistics-workflow/) + +Known issues / Roadmap +====================== + + +In standard odoo is possible to sort the purchase order lines and those are propagated to the invoice lines + +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 +~~~~~~~ + +* Camptocamp +* ForgeFlow +* Serpent CS + +Contributors +~~~~~~~~~~~~ + +* Cécile Jallais +* Damien Crier +* ForgeFlow S.L. +* Serpent Consulting Services Pvt. Ltd. + +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/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_order_line_sequence/__init__.py b/purchase_order_line_sequence/__init__.py new file mode 100644 index 00000000000..4b76c7b2d5c --- /dev/null +++ b/purchase_order_line_sequence/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/purchase_order_line_sequence/__manifest__.py b/purchase_order_line_sequence/__manifest__.py new file mode 100644 index 00000000000..8c7bd596963 --- /dev/null +++ b/purchase_order_line_sequence/__manifest__.py @@ -0,0 +1,31 @@ +# Copyright 2017 Camptocamp SA - Damien Crier, Alexandre Fayolle +# Copyright 2017 ForgeFlow S.L. +# Copyright 2017 Serpent Consulting Services Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Purchase Order Line Sequence", + "summary": "Adds sequence to PO lines and propagates it to" + "Invoice lines and Stock Moves", + "version": "16.0.1.0.0", + "category": "Purchase Management", + "author": "Camptocamp, " + "ForgeFlow, " + "Serpent CS, " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/purchase-workflow", + "depends": [ + "purchase_stock", + "stock_picking_line_sequence", + ], + "data": [ + "views/purchase_view.xml", + "views/report_purchaseorder.xml", + "views/report_purchasequotation.xml", + "views/account_move_view.xml", + "views/report_invoice.xml", + ], + "installable": True, + "auto_install": False, + "license": "AGPL-3", +} diff --git a/purchase_order_line_sequence/i18n/de.po b/purchase_order_line_sequence/i18n/de.po new file mode 100644 index 00000000000..ff5b958464c --- /dev/null +++ b/purchase_order_line_sequence/i18n/de.po @@ -0,0 +1,74 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_line_sequence +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: de\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" + +#. module: purchase_order_line_sequence +#: model_terms:ir.ui.view,arch_db:purchase_order_line_sequence.report_purchase_order_sequence_qweb +#: model_terms:ir.ui.view,arch_db:purchase_order_line_sequence.report_purchase_quote_sequence_qweb +msgid "Sequence" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__display_name +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__display_name +msgid "Display Name" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,help:purchase_order_line_sequence.field_purchase_order_line__sequence2 +msgid "Displays the sequence of the line in the purchase order." +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,help:purchase_order_line_sequence.field_purchase_order_line__sequence +msgid "Gives the sequence of the line when displaying the purchase order." +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__sequence +msgid "Hidden Sequence" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__id +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__id +msgid "ID" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order____last_update +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__max_line_sequence +msgid "Max sequence in lines" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__sequence2 +msgid "Sequence" +msgstr "" diff --git a/purchase_order_line_sequence/i18n/es.po b/purchase_order_line_sequence/i18n/es.po new file mode 100644 index 00000000000..04b7a6c71da --- /dev/null +++ b/purchase_order_line_sequence/i18n/es.po @@ -0,0 +1,76 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_line_sequence +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-05-29 19:08+0000\n" +"Last-Translator: JHernandezConinpe \n" +"Language-Team: none\n" +"Language: es\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.17\n" + +#. module: purchase_order_line_sequence +#: model_terms:ir.ui.view,arch_db:purchase_order_line_sequence.report_purchase_order_sequence_qweb +#: model_terms:ir.ui.view,arch_db:purchase_order_line_sequence.report_purchase_quote_sequence_qweb +msgid "Sequence" +msgstr "Número de línea" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__display_name +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,help:purchase_order_line_sequence.field_purchase_order_line__sequence2 +msgid "Displays the sequence of the line in the purchase order." +msgstr "Muestra la secuencia de la línea en el pedido de compra." + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,help:purchase_order_line_sequence.field_purchase_order_line__sequence +msgid "Gives the sequence of the line when displaying the purchase order." +msgstr "Indica la secuencia de la línea al visualizar el pedido de compra." + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__sequence +msgid "Hidden Sequence" +msgstr "Secuencia oculta" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__id +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__id +msgid "ID" +msgstr "ID" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order____last_update +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line____last_update +msgid "Last Modified on" +msgstr "Última modificación" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__max_line_sequence +msgid "Max sequence in lines" +msgstr "Secuencia máxima en líneas" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_purchase_order +msgid "Purchase Order" +msgstr "Pedido de compra" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Línea de pedido de compra" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__sequence2 +msgid "Sequence" +msgstr "Número de línea" diff --git a/purchase_order_line_sequence/i18n/fr.po b/purchase_order_line_sequence/i18n/fr.po new file mode 100644 index 00000000000..ad7b904d280 --- /dev/null +++ b/purchase_order_line_sequence/i18n/fr.po @@ -0,0 +1,67 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_reorder_lines +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-07-10 13:13+0000\n" +"PO-Revision-Date: 2020-08-28 17:00+0000\n" +"Last-Translator: Sandie FAVRE \n" +"Language-Team: \n" +"Language: fr\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 3.10\n" + +#. module: purchase_order_line_sequence +#: model_terms:ir.ui.view,arch_db:purchase_order_line_sequence.report_purchase_order_sequence_qweb +#: model_terms:ir.ui.view,arch_db:purchase_order_line_sequence.report_purchase_quote_sequence_qweb +msgid "Sequence" +msgstr "Séquence" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,help:purchase_order_line_sequence.field_purchase_order_line__sequence2 +msgid "Displays the sequence of the line in the purchase order." +msgstr "Affiche la séquence de la ligne dans l'ordre d'achat." + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,help:purchase_order_line_sequence.field_purchase_order_line__sequence +msgid "Gives the sequence of the line when displaying the purchase order." +msgstr "Donne la séquence de la ligne lors de l'affichage du bon de commande." + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__sequence +msgid "Hidden Sequence" +msgstr "Séquence masquée" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_account_invoice_line +msgid "Invoice Line" +msgstr "Ligne de facture" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__max_line_sequence +msgid "Max sequence in lines" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_purchase_order +msgid "Purchase Order" +msgstr "Bon de commande" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Ligne de bon de commande" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__sequence2 +msgid "Sequence" +msgstr "Séquence" + +#~ msgid "Purchase Order Line Make Invoice" +#~ msgstr "Créer la facture des lignes de commande d'achat" diff --git a/purchase_order_line_sequence/i18n/purchase_order_line_sequence.pot b/purchase_order_line_sequence/i18n/purchase_order_line_sequence.pot new file mode 100644 index 00000000000..370332343ac --- /dev/null +++ b/purchase_order_line_sequence/i18n/purchase_order_line_sequence.pot @@ -0,0 +1,73 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_line_sequence +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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: purchase_order_line_sequence +#: model_terms:ir.ui.view,arch_db:purchase_order_line_sequence.report_purchase_order_sequence_qweb +#: model_terms:ir.ui.view,arch_db:purchase_order_line_sequence.report_purchase_quote_sequence_qweb +msgid "Sequence" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__display_name +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__display_name +msgid "Display Name" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,help:purchase_order_line_sequence.field_purchase_order_line__sequence2 +msgid "Displays the sequence of the line in the purchase order." +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,help:purchase_order_line_sequence.field_purchase_order_line__sequence +msgid "Gives the sequence of the line when displaying the purchase order." +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__sequence +msgid "Hidden Sequence" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__id +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__id +msgid "ID" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order____last_update +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order__max_line_sequence +msgid "Max sequence in lines" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line__sequence2 +msgid "Sequence" +msgstr "" diff --git a/purchase_order_line_sequence/models/__init__.py b/purchase_order_line_sequence/models/__init__.py new file mode 100644 index 00000000000..62f66f4e170 --- /dev/null +++ b/purchase_order_line_sequence/models/__init__.py @@ -0,0 +1,6 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import purchase +from . import purchase_line +from . import account_move_line +from . import stock_move diff --git a/purchase_order_line_sequence/models/account_move_line.py b/purchase_order_line_sequence/models/account_move_line.py new file mode 100644 index 00000000000..71b62f29b6a --- /dev/null +++ b/purchase_order_line_sequence/models/account_move_line.py @@ -0,0 +1,24 @@ +# Copyright 2023 Forgeflow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + related_po_sequence = fields.Char( + string="PO Line Number", + compute="_compute_related_po_sequence", + ) + + @api.depends("move_id.invoice_line_ids") + def _compute_related_po_sequence(self): + for rec in self: + if len(rec.move_id.mapped("line_ids.purchase_order_id")) > 1: + rec.related_po_sequence = "{}/{}".format( + rec.purchase_line_id.order_id.name, + rec.purchase_line_id.visible_sequence, + ) + else: + rec.related_po_sequence = str(rec.purchase_line_id.visible_sequence) diff --git a/purchase_order_line_sequence/models/purchase.py b/purchase_order_line_sequence/models/purchase.py new file mode 100644 index 00000000000..78d4377fdeb --- /dev/null +++ b/purchase_order_line_sequence/models/purchase.py @@ -0,0 +1,57 @@ +# Copyright 2017 Camptocamp SA - Damien Crier, Alexandre Fayolle +# Copyright 2017 ForgeFlow S.L. +# Copyright 2017 Serpent Consulting Services Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + @api.depends("order_line") + def _compute_max_line_sequence(self): + """Allow to know the highest sequence entered in purchase order lines. + Then we add 1 to this value for the next sequence which is given + to the context of the o2m field in the view. So when we create a new + purchase order line, the sequence is automatically max_sequence + 1 + """ + for purchase in self: + purchase.max_line_sequence = ( + max(purchase.mapped("order_line.sequence") or [0]) + 1 + ) + + max_line_sequence = fields.Integer( + string="Max sequence in lines", compute="_compute_max_line_sequence" + ) + + def _create_picking(self): + res = super(PurchaseOrder, self)._create_picking() + self._update_moves_sequence() + return res + + def _update_moves_sequence(self): + for order in self: + if any( + [ + ptype in ["product", "consu"] + for ptype in order.order_line.mapped("product_id.type") + ] + ): + for picking in order.picking_ids: + for move in picking.move_ids: + if not move.purchase_line_id: + continue + move.write({"sequence": move.purchase_line_id.visible_sequence}) + + @api.model_create_multi + def create(self, vals_list): + res = super(PurchaseOrder, self).create(vals_list) + self._update_moves_sequence() + return res + + def write(self, line_values): + res = super(PurchaseOrder, self).write(line_values) + if "order_line" in line_values: + self._update_moves_sequence() + return res diff --git a/purchase_order_line_sequence/models/purchase_line.py b/purchase_order_line_sequence/models/purchase_line.py new file mode 100644 index 00000000000..48e0b66c1a8 --- /dev/null +++ b/purchase_order_line_sequence/models/purchase_line.py @@ -0,0 +1,33 @@ +# Copyright 2017 Camptocamp SA - Damien Crier, Alexandre Fayolle +# Copyright 2017 ForgeFlow S.L. +# Copyright 2017 Serpent Consulting Services Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + _order = "sequence, id" + + sequence = fields.Integer( + "Hidden Sequence", + help="Gives the sequence of the line when " "displaying the purchase order.", + default=9999, + ) + + visible_sequence = fields.Integer( + "Line Number", + help="Displays the sequence of the line in the purchase order.", + compute="_compute_visible_sequence", + store=True, + ) + + @api.depends("sequence", "order_id.order_line") + def _compute_visible_sequence(self): + for po in self.mapped("order_id"): + sequence = 1 + order_lines = po.order_line.filtered(lambda l: not l.display_type) + for line in sorted(order_lines, key=lambda l: l.sequence): + line.visible_sequence = sequence + sequence += 1 diff --git a/purchase_order_line_sequence/models/stock_move.py b/purchase_order_line_sequence/models/stock_move.py new file mode 100644 index 00000000000..badba224637 --- /dev/null +++ b/purchase_order_line_sequence/models/stock_move.py @@ -0,0 +1,19 @@ +# Copyright 2023 Forgeflow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, models +from odoo.exceptions import UserError + + +class StockMove(models.Model): + _inherit = "stock.move" + + @api.onchange("sequence") + def _onchange_sequence(self): + if self.purchase_line_id: + raise UserError( + _( + "Not allowed to change the sequence of moves from the picking, " + "you can do it from the PO." + ) + ) diff --git a/purchase_order_line_sequence/readme/CONTRIBUTORS.rst b/purchase_order_line_sequence/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..b1e1bbe2e2e --- /dev/null +++ b/purchase_order_line_sequence/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Cécile Jallais +* Damien Crier +* ForgeFlow S.L. +* Serpent Consulting Services Pvt. Ltd. diff --git a/purchase_order_line_sequence/readme/DESCRIPTION.rst b/purchase_order_line_sequence/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..ee248cdfc68 --- /dev/null +++ b/purchase_order_line_sequence/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ + +The sequence in PO line is propagated to the Stock moves. The sequence number +appears in the PO form view and in the report. diff --git a/purchase_order_line_sequence/readme/ROADMAP.rst b/purchase_order_line_sequence/readme/ROADMAP.rst new file mode 100644 index 00000000000..84ba43724a6 --- /dev/null +++ b/purchase_order_line_sequence/readme/ROADMAP.rst @@ -0,0 +1,2 @@ + +In standard odoo is possible to sort the purchase order lines and those are propagated to the invoice lines diff --git a/purchase_order_line_sequence/readme/USAGE.rst b/purchase_order_line_sequence/readme/USAGE.rst new file mode 100644 index 00000000000..1502b6c495c --- /dev/null +++ b/purchase_order_line_sequence/readme/USAGE.rst @@ -0,0 +1,3 @@ + +This module depends on the following module(s) : + * stock_picking_line_sequence (https://github.com/OCA/stock-logistics-workflow/) diff --git a/purchase_order_line_sequence/static/description/icon.png b/purchase_order_line_sequence/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_order_line_sequence/static/description/icon.png differ diff --git a/purchase_order_line_sequence/static/description/index.html b/purchase_order_line_sequence/static/description/index.html new file mode 100644 index 00000000000..2e7f2324ede --- /dev/null +++ b/purchase_order_line_sequence/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Purchase Order Line Sequence + + + +
+

Purchase Order Line Sequence

+ + +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runbot

+

The sequence in PO line is propagated to the Stock moves. The sequence number +appears in the PO form view and in the report.

+

Table of contents

+ +
+

Usage

+
+
This module depends on the following module(s) :
+
+
+
+
+
+

Known issues / Roadmap

+

In standard odoo is possible to sort the purchase order lines and those are propagated to the invoice lines

+
+
+

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

+
    +
  • Camptocamp
  • +
  • ForgeFlow
  • +
  • Serpent CS
  • +
+
+
+

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/purchase-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/purchase_order_line_sequence/tests/__init__.py b/purchase_order_line_sequence/tests/__init__.py new file mode 100644 index 00000000000..117ebd64788 --- /dev/null +++ b/purchase_order_line_sequence/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_po_lines_sequence diff --git a/purchase_order_line_sequence/tests/test_po_lines_sequence.py b/purchase_order_line_sequence/tests/test_po_lines_sequence.py new file mode 100644 index 00000000000..2cfcec5f8db --- /dev/null +++ b/purchase_order_line_sequence/tests/test_po_lines_sequence.py @@ -0,0 +1,271 @@ +# Copyright 2017 Camptocamp SA - Damien Crier, Alexandre Fayolle +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Serpent Consulting Services Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from datetime import datetime + +from odoo.tests import common, tagged +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT + + +@tagged("post_install", "-at_install") +class TestPurchaseOrder(common.TransactionCase): + def setUp(self): + super(TestPurchaseOrder, self).setUp() + # Useful models + self.PurchaseOrder = self.env["purchase.order"] + self.PurchaseOrderLine = self.env["purchase.order.line"] + self.partner_id = self.env.ref("base.res_partner_1") + self.product_id_1 = self.env.ref("product.product_product_8") + self.product_id_2 = self.env.ref("product.product_product_11") + + self.AccountInvoice = self.env["account.move"] + self.AccountInvoiceLine = self.env["account.move.line"] + + self.category = self.env.ref("product.product_category_1").copy( + { + "name": "Test category", + "property_valuation": "real_time", + "property_cost_method": "fifo", + } + ) + + self.account_expense = self.env["account.account"].create( + { + "name": "Expense", + "code": "EXP00", + "account_type": "liability_current", + "reconcile": True, + } + ) + self.account_payable = self.env["account.account"].create( + { + "name": "Payable", + "code": "PAY00", + "account_type": "liability_payable", + "reconcile": True, + } + ) + + self.category.property_account_expense_categ_id = self.account_expense + + self.category.property_stock_journal = self.env["account.journal"].create( + {"name": "Stock journal", "type": "sale", "code": "STK00"} + ) + self.product_id_1.categ_id = self.category + self.product_id_2.categ_id = self.category + self.partner_id.property_account_payable_id = self.account_payable + + def _create_purchase_order(self): + po_vals = { + "partner_id": self.partner_id.id, + "order_line": [ + ( + 0, + 0, + { + "name": self.product_id_1.name, + "product_id": self.product_id_1.id, + "product_qty": 5.0, + "product_uom": self.product_id_1.uom_po_id.id, + "price_unit": 500.0, + "date_planned": datetime.today().strftime( + DEFAULT_SERVER_DATETIME_FORMAT + ), + }, + ), + ( + 0, + 0, + { + "name": self.product_id_2.name, + "product_id": self.product_id_2.id, + "product_qty": 5.0, + "product_uom": self.product_id_2.uom_po_id.id, + "price_unit": 250.0, + "date_planned": datetime.today().strftime( + DEFAULT_SERVER_DATETIME_FORMAT + ), + }, + ), + ], + } + + return self.PurchaseOrder.create(po_vals) + + def test_purchase_order_line_sequence(self): + + self.po = self._create_purchase_order() + self.po.button_confirm() + + move1 = self.env["stock.move"].search( + [("purchase_line_id", "=", self.po.order_line[0].id)] + ) + move2 = self.env["stock.move"].search( + [("purchase_line_id", "=", self.po.order_line[1].id)] + ) + + self.assertEqual( + self.po.order_line[0].visible_sequence, + move1.sequence, + "The Sequence of the Purchase Order Lines does not " + "match to the Stock Moves", + ) + self.assertEqual( + self.po.order_line[1].visible_sequence, + move2.sequence, + "The Sequence of the Purchase Order Lines does not " + "match to the Stock Moves", + ) + + self.po2 = self.po.copy() + self.assertEqual( + self.po.order_line[0].visible_sequence, + self.po2.order_line[0].visible_sequence, + "The Sequence is not copied properly", + ) + self.assertEqual( + self.po.order_line[1].visible_sequence, + self.po2.order_line[1].visible_sequence, + "The Sequence is not copied properly", + ) + + def test_purchase_order_line_sequence_with_section_note(self): + """ + Verify that the sequence is correctly assigned to the move associated + with the purchase order line it references. + """ + po = self._create_purchase_order() + self.PurchaseOrderLine.create( + { + "name": "Section 1", + "display_type": "line_section", + "order_id": po.id, + "product_qty": 0, + } + ) + self.PurchaseOrderLine.create( + { + "name": self.product_id_1.name, + "product_id": self.product_id_1.id, + "product_qty": 15.0, + "product_uom": self.product_id_1.uom_po_id.id, + "price_unit": 150.0, + "date_planned": datetime.today().strftime( + DEFAULT_SERVER_DATETIME_FORMAT + ), + "order_id": po.id, + } + ) + self.PurchaseOrderLine.create( + { + "name": "Note 1", + "display_type": "line_note", + "order_id": po.id, + "product_qty": 0, + } + ) + self.PurchaseOrderLine.create( + { + "name": self.product_id_2.name, + "product_id": self.product_id_2.id, + "product_qty": 1.0, + "product_uom": self.product_id_2.uom_po_id.id, + "price_unit": 50.0, + "date_planned": datetime.today().strftime( + DEFAULT_SERVER_DATETIME_FORMAT + ), + "order_id": po.id, + } + ) + po.button_confirm() + + moves = po.picking_ids[0].move_ids_without_package + self.assertNotEqual(len(po.order_line), len(moves)) + + for move in moves: + self.assertEqual(move.sequence, move.purchase_line_id.visible_sequence) + + def test_write_purchase_order_line(self): + """ + Verify that the sequence is correctly assigned to the move associated + with the purchase order line it references when you modify it. + """ + po = self._create_purchase_order() + po.button_confirm() + + po.write( + { + "order_line": [ + ( + 0, + 0, + { + "name": self.product_id_2.name, + "product_id": self.product_id_2.id, + "product_qty": 2, + "product_uom": self.product_id_2.uom_id.id, + "price_unit": 30, + "date_planned": datetime.today().strftime( + DEFAULT_SERVER_DATETIME_FORMAT + ), + }, + ) + ] + } + ) + + moves = po.picking_ids[0].move_ids_without_package + for move in moves: + self.assertEqual(move.sequence, move.purchase_line_id.visible_sequence) + + def test_invoice_sequence(self): + """ + Verify that the sequence is correctly assigned to the account move associated + with the purchase order line it references. + """ + po = self._create_purchase_order() + po.button_confirm() + po.order_line.qty_received = 5 + result = po.action_create_invoice() + self.invoice = self.AccountInvoice.browse(result["res_id"]) + self.assertEqual( + str(po.order_line[0].visible_sequence), + self.invoice.line_ids[0].related_po_sequence, + ) + self.assertEqual( + str(po.order_line[1].visible_sequence), + self.invoice.line_ids[1].related_po_sequence, + ) + + def test_invoice_multiple_orders_sequence(self): + """ + Verify that the sequence is correctly assigned to the account move associated + with the purchase order line it references, + when adding different POs to the same invoice. + Format expected: + - PO12345/1 - PO Name + "/" + Sequence + """ + po = self._create_purchase_order() + po.button_confirm() + po.order_line.qty_received = 5 + po2 = self._create_purchase_order() + po2.button_confirm() + po2.order_line.qty_received = 2 + + orders = self.PurchaseOrder.search([("id", "in", [po.id, po2.id])]) + result = orders.action_create_invoice() + invoice = self.AccountInvoice.search([("id", "=", result["res_id"])], limit=1) + + self.assertTrue(invoice) + self.assertTrue(len(invoice.invoice_origin.split(",")), 2) + + self.assertEqual( + invoice.invoice_line_ids[0].related_po_sequence, + "{}/{}".format(po2.name, po2.order_line[0].visible_sequence), + ) + self.assertEqual( + invoice.invoice_line_ids[3].related_po_sequence, + "{}/{}".format(po.name, po.order_line[1].visible_sequence), + ) diff --git a/purchase_order_line_sequence/views/account_move_view.xml b/purchase_order_line_sequence/views/account_move_view.xml new file mode 100644 index 00000000000..3fc0f3d4e1f --- /dev/null +++ b/purchase_order_line_sequence/views/account_move_view.xml @@ -0,0 +1,20 @@ + + + + + account.move.form + account.move + + + + + + + + diff --git a/purchase_order_line_sequence/views/purchase_view.xml b/purchase_order_line_sequence/views/purchase_view.xml new file mode 100644 index 00000000000..aa58c360452 --- /dev/null +++ b/purchase_order_line_sequence/views/purchase_view.xml @@ -0,0 +1,37 @@ + + + + + purchase.order.line.form + purchase.order.line + + + + + + + + + + purchase.order.form + purchase.order + + 2 + + + + + + {'default_sequence': + max_line_sequence, 'default_state': 'draft'} + + + + + + + + diff --git a/purchase_order_line_sequence/views/report_invoice.xml b/purchase_order_line_sequence/views/report_invoice.xml new file mode 100644 index 00000000000..0033169c96e --- /dev/null +++ b/purchase_order_line_sequence/views/report_invoice.xml @@ -0,0 +1,24 @@ + + + + diff --git a/purchase_order_line_sequence/views/report_purchaseorder.xml b/purchase_order_line_sequence/views/report_purchaseorder.xml new file mode 100644 index 00000000000..5154f8799f0 --- /dev/null +++ b/purchase_order_line_sequence/views/report_purchaseorder.xml @@ -0,0 +1,17 @@ + + + + diff --git a/purchase_order_line_sequence/views/report_purchasequotation.xml b/purchase_order_line_sequence/views/report_purchasequotation.xml new file mode 100644 index 00000000000..323696c21e5 --- /dev/null +++ b/purchase_order_line_sequence/views/report_purchasequotation.xml @@ -0,0 +1,17 @@ + + + + diff --git a/setup/purchase_order_line_sequence/odoo/addons/purchase_order_line_sequence b/setup/purchase_order_line_sequence/odoo/addons/purchase_order_line_sequence new file mode 120000 index 00000000000..f1a3c2aa213 --- /dev/null +++ b/setup/purchase_order_line_sequence/odoo/addons/purchase_order_line_sequence @@ -0,0 +1 @@ +../../../../purchase_order_line_sequence \ No newline at end of file diff --git a/setup/purchase_order_line_sequence/setup.py b/setup/purchase_order_line_sequence/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/purchase_order_line_sequence/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)