From 99288dae58790fb8c996cd473821ca07b5931a23 Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Mon, 26 Sep 2016 12:16:11 +0530 Subject: [PATCH 01/36] [IMP] renamed the module name. --- purchase_order_line_sequence/README.rst | 69 ++++++++++++++++ purchase_order_line_sequence/__init__.py | 12 +++ purchase_order_line_sequence/__openerp__.py | 28 +++++++ purchase_order_line_sequence/i18n/fr.po | 42 ++++++++++ .../i18n/purchase_order_line_sequence.pot | 42 ++++++++++ .../models/__init__.py | 12 +++ .../models/invoice.py | 17 ++++ .../models/purchase.py | 46 +++++++++++ .../test/test_invoice_on_po_line.yml | 46 +++++++++++ .../tests/__init__.py | 11 +++ .../tests/test_invoice_on_lines.py | 80 +++++++++++++++++++ .../views/purchase_view.xml | 35 ++++++++ 12 files changed, 440 insertions(+) create mode 100644 purchase_order_line_sequence/README.rst create mode 100644 purchase_order_line_sequence/__init__.py create mode 100644 purchase_order_line_sequence/__openerp__.py create mode 100644 purchase_order_line_sequence/i18n/fr.po create mode 100644 purchase_order_line_sequence/i18n/purchase_order_line_sequence.pot create mode 100644 purchase_order_line_sequence/models/__init__.py create mode 100644 purchase_order_line_sequence/models/invoice.py create mode 100644 purchase_order_line_sequence/models/purchase.py create mode 100644 purchase_order_line_sequence/test/test_invoice_on_po_line.yml create mode 100644 purchase_order_line_sequence/tests/__init__.py create mode 100644 purchase_order_line_sequence/tests/test_invoice_on_lines.py create mode 100644 purchase_order_line_sequence/views/purchase_view.xml diff --git a/purchase_order_line_sequence/README.rst b/purchase_order_line_sequence/README.rst new file mode 100644 index 00000000000..8fbf3202286 --- /dev/null +++ b/purchase_order_line_sequence/README.rst @@ -0,0 +1,69 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +========================================= +Purchase order lines with sequence number +========================================= + +Provides a new field on the purchase order form, allowing to manage the order of the purchase order lines. + + +Installation +============ + +To install this module, you need to install its dependant module: + + * stock_picking_reorder_lines (https://github.com/OCA/stock-logistics-workflow/) + +Configuration +============= + +No configuration is required. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/142/9.0 + + +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 + + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Damien Crier +* Eficent Business and IT Consulting Services S.L. +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit http://odoo-community.org. + diff --git a/purchase_order_line_sequence/__init__.py b/purchase_order_line_sequence/__init__.py new file mode 100644 index 00000000000..a8a187060b4 --- /dev/null +++ b/purchase_order_line_sequence/__init__.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import models +from . import tests diff --git a/purchase_order_line_sequence/__openerp__.py b/purchase_order_line_sequence/__openerp__.py new file mode 100644 index 00000000000..2bca7952735 --- /dev/null +++ b/purchase_order_line_sequence/__openerp__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + 'name': 'Purchase order lines with sequence number', + 'version': '9.0.1.0.1', + 'category': 'Purchase Management', + 'author': "Camptocamp, " + "Eficent, " + "Serpent CS, " + "Odoo Community Association (OCA)", + 'website': 'http://www.camptocamp.com', + 'depends': [ + 'purchase', + 'stock_picking_reorder_lines', + ], + 'data': ['views/purchase_view.xml'], + 'installable': True, + 'auto_install': False, + 'license': "AGPL-3", +} diff --git a/purchase_order_line_sequence/i18n/fr.po b/purchase_order_line_sequence/i18n/fr.po new file mode 100644 index 00000000000..a2410e57f8a --- /dev/null +++ b/purchase_order_line_sequence/i18n/fr.po @@ -0,0 +1,42 @@ +# 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: 2015-07-10 13:13+0000\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_reorder_lines +#: help:purchase.order.line,sequence:0 +msgid "Gives the sequence of this line when displaying the purchase order." +msgstr "Numéro d'ordre des lines lors de l'affichage du bon de commande." + +#. module: purchase_order_reorder_lines +#: model:ir.model,name:purchase_order_reorder_lines.model_purchase_order_line_invoice +msgid "Purchase Order Line Make Invoice" +msgstr "Créer la facture des lignes de commande d'achat" + +#. module: purchase_order_reorder_lines +#: model:ir.model,name:purchase_order_reorder_lines.model_purchase_order_line +msgid "Purchase Order line" +msgstr "Purchase Order line" + +#. module: purchase_order_reorder_lines +#: model:ir.model,name:purchase_order_reorder_lines.model_purchase_order +msgid "Purchase order" +msgstr "Commande fournisseur" + +#. module: purchase_order_reorder_lines +#: field:purchase.order.line,sequence:0 +msgid "Sequence" +msgstr "Séquence" + 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..2a884ac6306 --- /dev/null +++ b/purchase_order_line_sequence/i18n/purchase_order_line_sequence.pot @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_line_sequence +# +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: 2015-07-10 13:13+0000\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 +#: help:purchase.order.line,sequence:0 +msgid "Gives the sequence of this line when displaying the purchase order." +msgstr "" + +#. module: purchase_order_line_sequence +#: model:ir.model,name:purchase_order_line_sequence.model_purchase_order_line_invoice +msgid "Purchase Order Line Make Invoice" +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,name:purchase_order_line_sequence.model_purchase_order +msgid "Purchase order" +msgstr "" + +#. module: purchase_order_line_sequence +#: field:purchase.order.line,sequence:0 +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..929f5001251 --- /dev/null +++ b/purchase_order_line_sequence/models/__init__.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import invoice +from . import purchase diff --git a/purchase_order_line_sequence/models/invoice.py b/purchase_order_line_sequence/models/invoice.py new file mode 100644 index 00000000000..51f5622eb9d --- /dev/null +++ b/purchase_order_line_sequence/models/invoice.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp import fields, models + + +class AccountInvoiceLine(models.Model): + _inherit = 'account.invoice.line' + + sequence = fields.Integer(related='purchase_line_id.sequence', store=True) diff --git a/purchase_order_line_sequence/models/purchase.py b/purchase_order_line_sequence/models/purchase.py new file mode 100644 index 00000000000..d79ac47120c --- /dev/null +++ b/purchase_order_line_sequence/models/purchase.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp import api, fields, models + + +class PurchaseOrderLine(models.Model): + _inherit = 'purchase.order.line' + _order = 'order_id desc, sequence, id' + + sequence = fields.Integer(help="Gives the sequence of this line when " + "displaying the purchase order.") + + @api.multi + def _create_stock_moves(self, picking): + res = super(PurchaseOrderLine, self)._create_stock_moves(picking) + for move, line in zip(res, self): + move.write({'sequence': line.sequence}) + return res + + +class PurchaseOrder(models.Model): + _inherit = 'purchase.order' + + @api.one + @api.depends('order_line') + def compute_max_line_sequence(self): + """Allow to know the highest sequence + entered in purchase order lines. + Web add 10 to this value for the next sequence + This value is given to the context of the o2m field + in the view. So when we create new purchase order lines, + the sequence is automatically max_sequence + 10 + """ + self.max_line_sequence = ( + max(self.mapped('order_line.sequence') or [0]) + 10) + + max_line_sequence = fields.Integer(string='Max sequence in lines', + compute='compute_max_line_sequence') diff --git a/purchase_order_line_sequence/test/test_invoice_on_po_line.yml b/purchase_order_line_sequence/test/test_invoice_on_po_line.yml new file mode 100644 index 00000000000..9d21898d2d9 --- /dev/null +++ b/purchase_order_line_sequence/test/test_invoice_on_po_line.yml @@ -0,0 +1,46 @@ +- + Create purchase_order +- + !record {model: purchase.order, id: purchase_order_8}: + partner_id: base.res_partner_22 + invoice_method: manual + order_line: + - product_id: product.product_product_38 + price_unit: 58 + product_qty: 9 + - product_id: product.product_product_39 + product_qty: 3 + price_unit: 65 + - product_id: product.product_product_44 + product_qty: 4 + price_unit: 154.5 +- + I check default sequence value +- + !python {model: purchase.order}: | + invoice_line_obj = self.pool.get('purchase.order.line_invoice') + purchase_order = self.browse(cr, uid, ref("purchase_order_8")) + for line in purchase_order.order_line: + assert line.sequence == 0, "Sequence should be 0 on all lines" +- + I confirm purchase order which has invoicing control method "Based on Purchase Order Lines". +- + !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_8} +- + In order to test create invoice for purchase order line. +- + !python {model: purchase.order}: | + invoice_line_obj = self.pool.get('purchase.order.line_invoice') + invoice_line_obj_id = invoice_line_obj.create(cr, uid, {}, context=context) + purchase_order = self.browse(cr, uid, ref("purchase_order_8")) + context.update({'active_model': 'purchase.order.line', 'active_ids': [pl.id for pl in purchase_order.order_line]}) + invoice_line_obj.makeInvoices(cr, uid, invoice_line_obj_id, context=context) +- + I check the invoice of order. +- + !python {model: purchase.order}: | + purchase_order = self.browse(cr, uid, ref("purchase_order_8")) + for purchase_line in purchase_order.order_line: + assert len(purchase_line.invoice_lines) == 1, "Invoice should be generated. 1 != %s" % (len(purchase_line.invoice_lines)) + for inv_line in purchase_line.invoice_lines: + assert purchase_line.sequence == inv_line.sequence, "Sequences should be the same" diff --git a/purchase_order_line_sequence/tests/__init__.py b/purchase_order_line_sequence/tests/__init__.py new file mode 100644 index 00000000000..c3b44cf4cbb --- /dev/null +++ b/purchase_order_line_sequence/tests/__init__.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import test_invoice_on_lines diff --git a/purchase_order_line_sequence/tests/test_invoice_on_lines.py b/purchase_order_line_sequence/tests/test_invoice_on_lines.py new file mode 100644 index 00000000000..5cdeba56a14 --- /dev/null +++ b/purchase_order_line_sequence/tests/test_invoice_on_lines.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from datetime import datetime +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT +from openerp.tests import common + + +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.AccountInvoice = self.env['account.invoice'] + self.AccountInvoiceLine = self.env['account.invoice.line'] + + def test_purchase_order(self): + 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') + + 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), + })], + } + self.po = self.PurchaseOrder.create(po_vals) + + self.po.button_confirm() + self.assertEqual(self.po.state, + 'purchase', + 'Purchase: PO state should be "Purchase"') + self.assertEqual(self.po.invoice_status, + 'to invoice', + 'PO invoice_status should be "Waiting Invoices"') + self.assertEqual(self.po.picking_count, 1, + 'Purchase: one picking should be created"') + self.picking = self.po.picking_ids[0] + self.picking.force_assign() + self.picking.pack_operation_product_ids.write({'qty_done': 5.0}) + self.picking.do_new_transfer() + self.assertEqual(self.po.order_line.mapped('qty_received'), + [5.0, 5.0], + 'Purchase: all products should be received"') + + self.invoice = self.AccountInvoice.create({ + 'partner_id': self.partner_id.id, + 'purchase_id': self.po.id, + 'account_id': self.partner_id.property_account_payable_id.id, + }) + self.invoice.purchase_order_change() + self.assertEqual(self.po.order_line.mapped('qty_invoiced'), + [5.0, 5.0], + 'Purchase: all products should be invoiced"') 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..56748226e45 --- /dev/null +++ b/purchase_order_line_sequence/views/purchase_view.xml @@ -0,0 +1,35 @@ + + + + + purchase.order.line.form + purchase.order.line + + + + + + + + + + purchase.order.form + purchase.order + + 2 + + + + + + {'default_sequence': max_line_sequence} + + + + + + + + + + From b9c531f3d984d467addd5c5637bfb7e5bc949b51 Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Wed, 28 Sep 2016 17:23:43 +0530 Subject: [PATCH 02/36] [ADD] added dependencies and sequences --- purchase_order_line_sequence/README.rst | 3 ++- purchase_order_line_sequence/__openerp__.py | 7 +++++-- purchase_order_line_sequence/models/__init__.py | 2 +- purchase_order_line_sequence/models/invoice.py | 7 +++++-- purchase_order_line_sequence/models/purchase.py | 10 +++++++--- .../views/purchase_view.xml | 7 ++++--- .../views/report_purchaseorder.xml | 15 +++++++++++++++ .../views/report_purchasequotation.xml | 15 +++++++++++++++ 8 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 purchase_order_line_sequence/views/report_purchaseorder.xml create mode 100644 purchase_order_line_sequence/views/report_purchasequotation.xml diff --git a/purchase_order_line_sequence/README.rst b/purchase_order_line_sequence/README.rst index 8fbf3202286..77683d90ae8 100644 --- a/purchase_order_line_sequence/README.rst +++ b/purchase_order_line_sequence/README.rst @@ -14,7 +14,8 @@ Installation To install this module, you need to install its dependant module: - * stock_picking_reorder_lines (https://github.com/OCA/stock-logistics-workflow/) + * stock_picking_line_sequence (https://github.com/OCA/stock-logistics-workflow/) + * account_invoice_line_sequence (https://github.com/OCA/account-invoicing/) Configuration ============= diff --git a/purchase_order_line_sequence/__openerp__.py b/purchase_order_line_sequence/__openerp__.py index 2bca7952735..a1d9411d306 100644 --- a/purchase_order_line_sequence/__openerp__.py +++ b/purchase_order_line_sequence/__openerp__.py @@ -19,9 +19,12 @@ 'website': 'http://www.camptocamp.com', 'depends': [ 'purchase', - 'stock_picking_reorder_lines', + 'stock_picking_line_sequence', + 'account_invoice_line_sequence', ], - 'data': ['views/purchase_view.xml'], + 'data': ['views/purchase_view.xml', + 'views/report_purchaseorder.xml', + 'views/report_purchasequotation.xml'], 'installable': True, 'auto_install': False, 'license': "AGPL-3", diff --git a/purchase_order_line_sequence/models/__init__.py b/purchase_order_line_sequence/models/__init__.py index 929f5001251..35184c45c89 100644 --- a/purchase_order_line_sequence/models/__init__.py +++ b/purchase_order_line_sequence/models/__init__.py @@ -8,5 +8,5 @@ # © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from . import invoice from . import purchase +from . import invoice diff --git a/purchase_order_line_sequence/models/invoice.py b/purchase_order_line_sequence/models/invoice.py index 51f5622eb9d..ef8775c4e69 100644 --- a/purchase_order_line_sequence/models/invoice.py +++ b/purchase_order_line_sequence/models/invoice.py @@ -8,10 +8,13 @@ # © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp import fields, models +from openerp import api, fields, models class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line' - sequence = fields.Integer(related='purchase_line_id.sequence', store=True) + def _set_additional_fields(self, invoice): + if self.purchase_line_id: + self.sequence = self.purchase_line_id.sequence + super(AccountInvoiceLine, self)._set_additional_fields(invoice) diff --git a/purchase_order_line_sequence/models/purchase.py b/purchase_order_line_sequence/models/purchase.py index d79ac47120c..1e6ecb71131 100644 --- a/purchase_order_line_sequence/models/purchase.py +++ b/purchase_order_line_sequence/models/purchase.py @@ -18,6 +18,10 @@ class PurchaseOrderLine(models.Model): sequence = fields.Integer(help="Gives the sequence of this line when " "displaying the purchase order.") + sequence2 = fields.Integer(help="Shows the sequence of this line in " + "the purchase order.", + related='sequence', readonly=True) + @api.multi def _create_stock_moves(self, picking): res = super(PurchaseOrderLine, self)._create_stock_moves(picking) @@ -34,13 +38,13 @@ class PurchaseOrder(models.Model): def compute_max_line_sequence(self): """Allow to know the highest sequence entered in purchase order lines. - Web add 10 to this value for the next sequence + Web add 1 to this value for the next sequence This value is given to the context of the o2m field in the view. So when we create new purchase order lines, - the sequence is automatically max_sequence + 10 + the sequence is automatically max_sequence + 1 """ self.max_line_sequence = ( - max(self.mapped('order_line.sequence') or [0]) + 10) + max(self.mapped('order_line.sequence') or [0]) + 1) max_line_sequence = fields.Integer(string='Max sequence in lines', compute='compute_max_line_sequence') diff --git a/purchase_order_line_sequence/views/purchase_view.xml b/purchase_order_line_sequence/views/purchase_view.xml index 56748226e45..11b93bce602 100644 --- a/purchase_order_line_sequence/views/purchase_view.xml +++ b/purchase_order_line_sequence/views/purchase_view.xml @@ -7,7 +7,7 @@ - + @@ -27,9 +27,10 @@ - + + + - 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..5e1e93ba981 --- /dev/null +++ b/purchase_order_line_sequence/views/report_purchaseorder.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file 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..25a6bcb1efd --- /dev/null +++ b/purchase_order_line_sequence/views/report_purchasequotation.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file From be59c04dfc819beceaa879b27579c7bd3960c06e Mon Sep 17 00:00:00 2001 From: darshan-serpent Date: Mon, 6 Mar 2017 19:08:14 +0530 Subject: [PATCH 03/36] [IMP] test cases --- .../models/invoice.py | 2 +- .../models/purchase.py | 77 +++++++++++---- .../test/test_invoice_on_po_line.yml | 46 --------- .../tests/__init__.py | 2 +- .../tests/test_invoice_on_lines.py | 80 ---------------- .../tests/test_po_lines_sequence.py | 96 +++++++++++++++++++ .../views/report_purchaseorder.xml | 2 +- .../views/report_purchasequotation.xml | 2 +- 8 files changed, 158 insertions(+), 149 deletions(-) delete mode 100644 purchase_order_line_sequence/test/test_invoice_on_po_line.yml delete mode 100644 purchase_order_line_sequence/tests/test_invoice_on_lines.py create mode 100644 purchase_order_line_sequence/tests/test_po_lines_sequence.py diff --git a/purchase_order_line_sequence/models/invoice.py b/purchase_order_line_sequence/models/invoice.py index ef8775c4e69..c55395489f3 100644 --- a/purchase_order_line_sequence/models/invoice.py +++ b/purchase_order_line_sequence/models/invoice.py @@ -8,7 +8,7 @@ # © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp import api, fields, models +from openerp import models class AccountInvoiceLine(models.Model): diff --git a/purchase_order_line_sequence/models/purchase.py b/purchase_order_line_sequence/models/purchase.py index 1e6ecb71131..cc2a9d62c87 100644 --- a/purchase_order_line_sequence/models/purchase.py +++ b/purchase_order_line_sequence/models/purchase.py @@ -11,12 +11,54 @@ from openerp 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. + Web add 1 to this value for the next sequence + This value is given to the context of the o2m field + in the view. So when we create new purchase order lines, + the sequence is automatically max_sequence + 1 + """ + self.max_line_sequence = ( + max(self.mapped('order_line.sequence') or [0]) + 1) + + max_line_sequence = fields.Integer(string='Max sequence in lines', + compute='_compute_max_line_sequence') + + @api.multi + def _reset_sequence(self): + for rec in self: + current_sequence = 1 + for line in rec.order_line: + line.write({'sequence': current_sequence}) + current_sequence += 1 + + @api.multi + def write(self, line_values): + res = super(PurchaseOrder, self).write(line_values) + for rec in self: + rec._reset_sequence() + return res + + @api.multi + def copy(self, default=None): + if not default: + default = {} + self2 = self.with_context(keep_line_sequence=True) + return super(PurchaseOrder, self2).copy(default) + + class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' _order = 'order_id desc, sequence, id' sequence = fields.Integer(help="Gives the sequence of this line when " - "displaying the purchase order.") + "displaying the purchase order.", + default=9999) sequence2 = fields.Integer(help="Shows the sequence of this line in " "the purchase order.", @@ -29,22 +71,19 @@ def _create_stock_moves(self, picking): move.write({'sequence': line.sequence}) return res + @api.model + def create(self, values): + line = super(PurchaseOrderLine, self).create(values) + # We do not reset the sequence if we are copying a complete purchase + # order + if 'keep_line_sequence' not in self.env.context: + line.order_id._reset_sequence() + return line -class PurchaseOrder(models.Model): - _inherit = 'purchase.order' - - @api.one - @api.depends('order_line') - def compute_max_line_sequence(self): - """Allow to know the highest sequence - entered in purchase order lines. - Web add 1 to this value for the next sequence - This value is given to the context of the o2m field - in the view. So when we create new purchase order lines, - the sequence is automatically max_sequence + 1 - """ - self.max_line_sequence = ( - max(self.mapped('order_line.sequence') or [0]) + 1) - - max_line_sequence = fields.Integer(string='Max sequence in lines', - compute='compute_max_line_sequence') + @api.multi + def copy(self, default=None): + if not default: + default = {} + if 'keep_line_sequence' not in self.env.context: + default['sequence'] = 9999 + return super(PurchaseOrderLine, self).copy(default) diff --git a/purchase_order_line_sequence/test/test_invoice_on_po_line.yml b/purchase_order_line_sequence/test/test_invoice_on_po_line.yml deleted file mode 100644 index 9d21898d2d9..00000000000 --- a/purchase_order_line_sequence/test/test_invoice_on_po_line.yml +++ /dev/null @@ -1,46 +0,0 @@ -- - Create purchase_order -- - !record {model: purchase.order, id: purchase_order_8}: - partner_id: base.res_partner_22 - invoice_method: manual - order_line: - - product_id: product.product_product_38 - price_unit: 58 - product_qty: 9 - - product_id: product.product_product_39 - product_qty: 3 - price_unit: 65 - - product_id: product.product_product_44 - product_qty: 4 - price_unit: 154.5 -- - I check default sequence value -- - !python {model: purchase.order}: | - invoice_line_obj = self.pool.get('purchase.order.line_invoice') - purchase_order = self.browse(cr, uid, ref("purchase_order_8")) - for line in purchase_order.order_line: - assert line.sequence == 0, "Sequence should be 0 on all lines" -- - I confirm purchase order which has invoicing control method "Based on Purchase Order Lines". -- - !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_8} -- - In order to test create invoice for purchase order line. -- - !python {model: purchase.order}: | - invoice_line_obj = self.pool.get('purchase.order.line_invoice') - invoice_line_obj_id = invoice_line_obj.create(cr, uid, {}, context=context) - purchase_order = self.browse(cr, uid, ref("purchase_order_8")) - context.update({'active_model': 'purchase.order.line', 'active_ids': [pl.id for pl in purchase_order.order_line]}) - invoice_line_obj.makeInvoices(cr, uid, invoice_line_obj_id, context=context) -- - I check the invoice of order. -- - !python {model: purchase.order}: | - purchase_order = self.browse(cr, uid, ref("purchase_order_8")) - for purchase_line in purchase_order.order_line: - assert len(purchase_line.invoice_lines) == 1, "Invoice should be generated. 1 != %s" % (len(purchase_line.invoice_lines)) - for inv_line in purchase_line.invoice_lines: - assert purchase_line.sequence == inv_line.sequence, "Sequences should be the same" diff --git a/purchase_order_line_sequence/tests/__init__.py b/purchase_order_line_sequence/tests/__init__.py index c3b44cf4cbb..26e81335ce5 100644 --- a/purchase_order_line_sequence/tests/__init__.py +++ b/purchase_order_line_sequence/tests/__init__.py @@ -8,4 +8,4 @@ # © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from . import test_invoice_on_lines +from . import test_po_lines_sequence diff --git a/purchase_order_line_sequence/tests/test_invoice_on_lines.py b/purchase_order_line_sequence/tests/test_invoice_on_lines.py deleted file mode 100644 index 5cdeba56a14..00000000000 --- a/purchase_order_line_sequence/tests/test_invoice_on_lines.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding: utf-8 -*- -# Author: Alexandre Fayolle -# Copyright 2013 Camptocamp SA -# Author: Damien Crier -# Copyright 2015 Camptocamp SA -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). - -from datetime import datetime -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT -from openerp.tests import common - - -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.AccountInvoice = self.env['account.invoice'] - self.AccountInvoiceLine = self.env['account.invoice.line'] - - def test_purchase_order(self): - 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') - - 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), - })], - } - self.po = self.PurchaseOrder.create(po_vals) - - self.po.button_confirm() - self.assertEqual(self.po.state, - 'purchase', - 'Purchase: PO state should be "Purchase"') - self.assertEqual(self.po.invoice_status, - 'to invoice', - 'PO invoice_status should be "Waiting Invoices"') - self.assertEqual(self.po.picking_count, 1, - 'Purchase: one picking should be created"') - self.picking = self.po.picking_ids[0] - self.picking.force_assign() - self.picking.pack_operation_product_ids.write({'qty_done': 5.0}) - self.picking.do_new_transfer() - self.assertEqual(self.po.order_line.mapped('qty_received'), - [5.0, 5.0], - 'Purchase: all products should be received"') - - self.invoice = self.AccountInvoice.create({ - 'partner_id': self.partner_id.id, - 'purchase_id': self.po.id, - 'account_id': self.partner_id.property_account_payable_id.id, - }) - self.invoice.purchase_order_change() - self.assertEqual(self.po.order_line.mapped('qty_invoiced'), - [5.0, 5.0], - 'Purchase: all products should be invoiced"') 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..17a9614f57b --- /dev/null +++ b/purchase_order_line_sequence/tests/test_po_lines_sequence.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +# Author: Alexandre Fayolle +# Copyright 2013 Camptocamp SA +# Author: Damien Crier +# Copyright 2015 Camptocamp SA +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from datetime import datetime +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT +from openerp.tests import common + + +class TestPurchaseOrder(common.TransactionCase): + + def setUp(self): + super(TestPurchaseOrder, self).setUp() + # Useful models + self.PurchaseOrder = self.env['purchase.order'] + self.Invoice = self.env['account.invoice'] + self.PurchaseOrderLine = self.env['purchase.order.line'] + self.InvoiceLine = self.env['account.invoice.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') + + 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].sequence, + move1.sequence, + 'The Sequence of the Purchase Order Lines does not ' + 'match to the Stock Moves') + self.assertEqual(self.po.order_line[1].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].sequence, + self.po2.order_line[0].sequence, + 'The Sequence is not copied properly') + self.assertEqual(self.po.order_line[1].sequence, + self.po2.order_line[1].sequence, + 'The Sequence is not copied properly') + + def test_invoice_sequence(self): + + po = self._create_purchase_order() + + invoice = self.Invoice.create({'partner_id': self.partner_id.id}) + invoice.purchase_id = po.id + invoice.currency_id = self.env.ref('base.INR').id, + invoice.purchase_order_change() + + self.assertEqual(po.order_line[0].sequence, + invoice.invoice_line_ids[0].sequence, + 'The Sequence is not copied properly') + self.assertEqual(po.order_line[1].sequence, + invoice.invoice_line_ids[1].sequence, + 'The Sequence is not copied properly') diff --git a/purchase_order_line_sequence/views/report_purchaseorder.xml b/purchase_order_line_sequence/views/report_purchaseorder.xml index 5e1e93ba981..125a2d19cbe 100644 --- a/purchase_order_line_sequence/views/report_purchaseorder.xml +++ b/purchase_order_line_sequence/views/report_purchaseorder.xml @@ -12,4 +12,4 @@ - \ No newline at end of file + diff --git a/purchase_order_line_sequence/views/report_purchasequotation.xml b/purchase_order_line_sequence/views/report_purchasequotation.xml index 25a6bcb1efd..f53aa8b58c6 100644 --- a/purchase_order_line_sequence/views/report_purchasequotation.xml +++ b/purchase_order_line_sequence/views/report_purchasequotation.xml @@ -12,4 +12,4 @@ - \ No newline at end of file + From 3aa667953b724f8d97fd935dadc08ae25f452da5 Mon Sep 17 00:00:00 2001 From: Darshan Patel Date: Fri, 30 Jun 2017 16:07:01 +0530 Subject: [PATCH 04/36] [ADD] purchase_order_line_sequence v10 --- purchase_order_line_sequence/README.rst | 20 ++---- purchase_order_line_sequence/__init__.py | 14 ++--- .../{__openerp__.py => __manifest__.py} | 19 +++--- purchase_order_line_sequence/hooks.py | 16 +++++ .../models/__init__.py | 12 ++-- .../models/invoice.py | 14 ++--- .../models/purchase.py | 61 +++++++------------ .../tests/__init__.py | 12 ++-- .../tests/test_po_lines_sequence.py | 16 ++--- .../views/purchase_view.xml | 55 ++++++++--------- .../views/report_purchaseorder.xml | 26 ++++---- .../views/report_purchasequotation.xml | 26 ++++---- 12 files changed, 125 insertions(+), 166 deletions(-) rename purchase_order_line_sequence/{__openerp__.py => __manifest__.py} (56%) create mode 100644 purchase_order_line_sequence/hooks.py diff --git a/purchase_order_line_sequence/README.rst b/purchase_order_line_sequence/README.rst index 77683d90ae8..2140f2d07a7 100644 --- a/purchase_order_line_sequence/README.rst +++ b/purchase_order_line_sequence/README.rst @@ -6,28 +6,16 @@ Purchase order lines with sequence number ========================================= -Provides a new field on the purchase order form, allowing to manage the order of the purchase order lines. +Provides a new field sequence on the purchase order, which allows to manage the order of its purchase order lines. +The sequence then is propagated to the Invoice lines and the Stock Moves. -Installation -============ - -To install this module, you need to install its dependant module: - - * stock_picking_line_sequence (https://github.com/OCA/stock-logistics-workflow/) - * account_invoice_line_sequence (https://github.com/OCA/account-invoicing/) - -Configuration -============= - -No configuration is required. - Usage ===== .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/142/9.0 + :target: https://runbot.odoo-community.org/runbot/142/10.0 Bug Tracker @@ -66,5 +54,5 @@ 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. -To contribute to this module, please visit http://odoo-community.org. +To contribute to this module, please visit https://odoo-community.org. diff --git a/purchase_order_line_sequence/__init__.py b/purchase_order_line_sequence/__init__.py index a8a187060b4..429738e8ccf 100644 --- a/purchase_order_line_sequence/__init__.py +++ b/purchase_order_line_sequence/__init__.py @@ -1,12 +1,8 @@ # -*- coding: utf-8 -*- -# Author: Alexandre Fayolle -# Copyright 2013 Camptocamp SA -# Author: Damien Crier -# Copyright 2015 Camptocamp SA -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# 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 . import models -from . import tests +from .hooks import post_init_hook diff --git a/purchase_order_line_sequence/__openerp__.py b/purchase_order_line_sequence/__manifest__.py similarity index 56% rename from purchase_order_line_sequence/__openerp__.py rename to purchase_order_line_sequence/__manifest__.py index a1d9411d306..63a4b702b33 100644 --- a/purchase_order_line_sequence/__openerp__.py +++ b/purchase_order_line_sequence/__manifest__.py @@ -1,16 +1,14 @@ # -*- coding: utf-8 -*- -# Author: Alexandre Fayolle -# Copyright 2013 Camptocamp SA -# Author: Damien Crier -# Copyright 2015 Camptocamp SA -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# 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). { 'name': 'Purchase order lines with sequence number', - 'version': '9.0.1.0.1', + 'summary': 'Adds sequence to PO lines and propagates it to' + 'Invoice lines and Stock Moves', + 'version': '10.0.1.0.0', 'category': 'Purchase Management', 'author': "Camptocamp, " "Eficent, " @@ -19,12 +17,11 @@ 'website': 'http://www.camptocamp.com', 'depends': [ 'purchase', - 'stock_picking_line_sequence', - 'account_invoice_line_sequence', ], 'data': ['views/purchase_view.xml', 'views/report_purchaseorder.xml', 'views/report_purchasequotation.xml'], + 'post_init_hook': 'post_init_hook', 'installable': True, 'auto_install': False, 'license': "AGPL-3", diff --git a/purchase_order_line_sequence/hooks.py b/purchase_order_line_sequence/hooks.py new file mode 100644 index 00000000000..51ae062f0c4 --- /dev/null +++ b/purchase_order_line_sequence/hooks.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# 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 odoo import SUPERUSER_ID +from odoo.api import Environment + + +def post_init_hook(cr, pool): + """ + Fetches all the PO and resets the sequence of the purchase order lines. + """ + env = Environment(cr, SUPERUSER_ID, {}) + purchase = env['purchase.order'].search([]) + purchase._reset_sequence() diff --git a/purchase_order_line_sequence/models/__init__.py b/purchase_order_line_sequence/models/__init__.py index 35184c45c89..8ac44a6e646 100644 --- a/purchase_order_line_sequence/models/__init__.py +++ b/purchase_order_line_sequence/models/__init__.py @@ -1,12 +1,8 @@ # -*- coding: utf-8 -*- -# Author: Alexandre Fayolle -# Copyright 2013 Camptocamp SA -# Author: Damien Crier -# Copyright 2015 Camptocamp SA -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# 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 . import purchase from . import invoice diff --git a/purchase_order_line_sequence/models/invoice.py b/purchase_order_line_sequence/models/invoice.py index c55395489f3..f0159de0482 100644 --- a/purchase_order_line_sequence/models/invoice.py +++ b/purchase_order_line_sequence/models/invoice.py @@ -1,14 +1,10 @@ # -*- coding: utf-8 -*- -# Author: Alexandre Fayolle -# Copyright 2013 Camptocamp SA -# Author: Damien Crier -# Copyright 2015 Camptocamp SA -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# 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 openerp import models +from odoo import models class AccountInvoiceLine(models.Model): diff --git a/purchase_order_line_sequence/models/purchase.py b/purchase_order_line_sequence/models/purchase.py index cc2a9d62c87..3874d45dabc 100644 --- a/purchase_order_line_sequence/models/purchase.py +++ b/purchase_order_line_sequence/models/purchase.py @@ -1,30 +1,26 @@ # -*- coding: utf-8 -*- -# Author: Alexandre Fayolle -# Copyright 2013 Camptocamp SA -# Author: Damien Crier -# Copyright 2015 Camptocamp SA -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# 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 openerp import api, fields, models +from odoo import api, fields, models class PurchaseOrder(models.Model): _inherit = 'purchase.order' + @api.multi @api.depends('order_line') def _compute_max_line_sequence(self): - """Allow to know the highest sequence - entered in purchase order lines. - Web add 1 to this value for the next sequence - This value is given to the context of the o2m field - in the view. So when we create new purchase order lines, - the sequence is automatically max_sequence + 1 + """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 """ - self.max_line_sequence = ( - max(self.mapped('order_line.sequence') or [0]) + 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') @@ -34,34 +30,31 @@ def _reset_sequence(self): for rec in self: current_sequence = 1 for line in rec.order_line: - line.write({'sequence': current_sequence}) + line.sequence = current_sequence current_sequence += 1 @api.multi def write(self, line_values): res = super(PurchaseOrder, self).write(line_values) - for rec in self: - rec._reset_sequence() + self._reset_sequence() return res @api.multi def copy(self, default=None): - if not default: - default = {} - self2 = self.with_context(keep_line_sequence=True) - return super(PurchaseOrder, self2).copy(default) + return super(PurchaseOrder, + self.with_context(keep_line_sequence=True)).copy(default) class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' - _order = 'order_id desc, sequence, id' + _order = 'sequence, id' - sequence = fields.Integer(help="Gives the sequence of this line when " + sequence = fields.Integer(help="Gives the sequence of the line when " "displaying the purchase order.", default=9999) - sequence2 = fields.Integer(help="Shows the sequence of this line in " - "the purchase order.", + sequence2 = fields.Integer(help="Displays the sequence of the line in " + "the purchase order.", related='sequence', readonly=True) @api.multi @@ -74,16 +67,8 @@ def _create_stock_moves(self, picking): @api.model def create(self, values): line = super(PurchaseOrderLine, self).create(values) - # We do not reset the sequence if we are copying a complete purchase + # We do reset the sequence if we are copying a complete purchase # order - if 'keep_line_sequence' not in self.env.context: + if self.env.context.get('keep_line_sequence'): line.order_id._reset_sequence() return line - - @api.multi - def copy(self, default=None): - if not default: - default = {} - if 'keep_line_sequence' not in self.env.context: - default['sequence'] = 9999 - return super(PurchaseOrderLine, self).copy(default) diff --git a/purchase_order_line_sequence/tests/__init__.py b/purchase_order_line_sequence/tests/__init__.py index 26e81335ce5..06b1748392d 100644 --- a/purchase_order_line_sequence/tests/__init__.py +++ b/purchase_order_line_sequence/tests/__init__.py @@ -1,11 +1,7 @@ # -*- coding: utf-8 -*- -# Author: Alexandre Fayolle -# Copyright 2013 Camptocamp SA -# Author: Damien Crier -# Copyright 2015 Camptocamp SA -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# 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 . 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 index 17a9614f57b..761ca5d7247 100644 --- a/purchase_order_line_sequence/tests/test_po_lines_sequence.py +++ b/purchase_order_line_sequence/tests/test_po_lines_sequence.py @@ -1,16 +1,12 @@ # -*- coding: utf-8 -*- -# Author: Alexandre Fayolle -# Copyright 2013 Camptocamp SA -# Author: Damien Crier -# Copyright 2015 Camptocamp SA -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# 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 openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT -from openerp.tests import common +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo.tests import common class TestPurchaseOrder(common.TransactionCase): diff --git a/purchase_order_line_sequence/views/purchase_view.xml b/purchase_order_line_sequence/views/purchase_view.xml index 11b93bce602..db8509ef9f5 100644 --- a/purchase_order_line_sequence/views/purchase_view.xml +++ b/purchase_order_line_sequence/views/purchase_view.xml @@ -1,36 +1,33 @@ - - purchase.order.line.form - purchase.order.line - - - - - + + purchase.order.line.form + purchase.order.line + + + + - + + - - purchase.order.form - purchase.order - - 2 - - - - - - {'default_sequence': max_line_sequence} - - - - - - - - - + + purchase.order.form + purchase.order + + 2 + + + + + + {'default_sequence': max_line_sequence} + + + + + + diff --git a/purchase_order_line_sequence/views/report_purchaseorder.xml b/purchase_order_line_sequence/views/report_purchaseorder.xml index 125a2d19cbe..6897229a0eb 100644 --- a/purchase_order_line_sequence/views/report_purchaseorder.xml +++ b/purchase_order_line_sequence/views/report_purchaseorder.xml @@ -1,15 +1,13 @@ - - - - - + + + diff --git a/purchase_order_line_sequence/views/report_purchasequotation.xml b/purchase_order_line_sequence/views/report_purchasequotation.xml index f53aa8b58c6..319184cb69d 100644 --- a/purchase_order_line_sequence/views/report_purchasequotation.xml +++ b/purchase_order_line_sequence/views/report_purchasequotation.xml @@ -1,15 +1,13 @@ - - - - - + + + From 111760e65195c0542b1506d73fd4c4684b4adb64 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 15 Mar 2018 12:25:46 +0000 Subject: [PATCH 05/36] [ADD] Missing dependency --- purchase_order_line_sequence/README.rst | 3 +++ purchase_order_line_sequence/__manifest__.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/purchase_order_line_sequence/README.rst b/purchase_order_line_sequence/README.rst index 2140f2d07a7..6a8d140d679 100644 --- a/purchase_order_line_sequence/README.rst +++ b/purchase_order_line_sequence/README.rst @@ -13,6 +13,9 @@ The sequence then is propagated to the Invoice lines and the Stock Moves. Usage ===== +-This module depends on the following module(s) : +- * stock_picking_line_sequence (https://github.com/OCA/stock-logistics-workflow/) + .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot :target: https://runbot.odoo-community.org/runbot/142/10.0 diff --git a/purchase_order_line_sequence/__manifest__.py b/purchase_order_line_sequence/__manifest__.py index 63a4b702b33..8fdb7fd68a8 100644 --- a/purchase_order_line_sequence/__manifest__.py +++ b/purchase_order_line_sequence/__manifest__.py @@ -16,7 +16,7 @@ "Odoo Community Association (OCA)", 'website': 'http://www.camptocamp.com', 'depends': [ - 'purchase', + 'purchase', 'stock_picking_line_sequence', ], 'data': ['views/purchase_view.xml', 'views/report_purchaseorder.xml', From dd720e1c2404b1f53b075d37a9dc37efe51381f7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 26 Mar 2018 07:51:09 +0100 Subject: [PATCH 06/36] [FIX] Bug in the logic of the module If the creation of purchase order lines is made with form view rather than tree view then the module misbehaves, ie, creates a line with sequence 9999. This fixes that without breaking the tree view usage. It also makes sure that the sequence is kept when duplicating a purchase order, which makes more sense. It seems that this was a typo/bug on the original module which was not manifestating when using tree view but becomes clear when allowing editing of the purchase order line with form view. --- purchase_order_line_sequence/models/purchase.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/purchase_order_line_sequence/models/purchase.py b/purchase_order_line_sequence/models/purchase.py index 3874d45dabc..e6cf10cc74d 100644 --- a/purchase_order_line_sequence/models/purchase.py +++ b/purchase_order_line_sequence/models/purchase.py @@ -67,8 +67,7 @@ def _create_stock_moves(self, picking): @api.model def create(self, values): line = super(PurchaseOrderLine, self).create(values) - # We do reset the sequence if we are copying a complete purchase - # order - if self.env.context.get('keep_line_sequence'): + # We do not reset the sequence when copying an entire purchase order + if not self.env.context.get('keep_line_sequence'): line.order_id._reset_sequence() return line From 4896d18aa5d65eb5fdecb8bc286a8da130e6d306 Mon Sep 17 00:00:00 2001 From: mreficent Date: Thu, 26 Jul 2018 14:12:47 +0200 Subject: [PATCH 07/36] [FIX] Assure sequence of stock moves are the same as of po lines --- purchase_order_line_sequence/models/purchase.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/purchase_order_line_sequence/models/purchase.py b/purchase_order_line_sequence/models/purchase.py index e6cf10cc74d..507221a93c6 100644 --- a/purchase_order_line_sequence/models/purchase.py +++ b/purchase_order_line_sequence/models/purchase.py @@ -25,6 +25,20 @@ def _compute_max_line_sequence(self): max_line_sequence = fields.Integer(string='Max sequence in lines', compute='_compute_max_line_sequence') + @api.multi + def _create_picking(self): + res = super(PurchaseOrder, self)._create_picking() + for order in self: + if any([ptype in ['product', 'consu'] for ptype in + order.order_line.mapped('product_id.type')]): + picking = order.picking_ids.filtered( + lambda x: x.state not in ('done', 'cancel'))[0] + for move, line in zip( + sorted(picking.move_lines, + key=lambda m: m.id), order.order_line): + move.write({'sequence': line.sequence}) + return res + @api.multi def _reset_sequence(self): for rec in self: From 3ebded2cf7c4b7663fb4dd5348aee1c22837a6ee Mon Sep 17 00:00:00 2001 From: mreficent Date: Thu, 26 Jul 2018 18:34:04 +0200 Subject: [PATCH 08/36] [FIX] Correct a test. Products are in purchase_method 'receive' --- purchase_order_line_sequence/tests/test_po_lines_sequence.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/purchase_order_line_sequence/tests/test_po_lines_sequence.py b/purchase_order_line_sequence/tests/test_po_lines_sequence.py index 761ca5d7247..cc5a58558f4 100644 --- a/purchase_order_line_sequence/tests/test_po_lines_sequence.py +++ b/purchase_order_line_sequence/tests/test_po_lines_sequence.py @@ -78,6 +78,8 @@ def test_purchase_order_line_sequence(self): def test_invoice_sequence(self): po = self._create_purchase_order() + po.button_confirm() + po.picking_ids.do_transfer() invoice = self.Invoice.create({'partner_id': self.partner_id.id}) invoice.purchase_id = po.id From fbb74b960b0eb078f47c9a02a76cd09161567ad5 Mon Sep 17 00:00:00 2001 From: oca-travis Date: Mon, 30 Jul 2018 10:15:02 +0000 Subject: [PATCH 09/36] [UPD] Update purchase_order_line_sequence.pot --- .../i18n/purchase_order_line_sequence.pot | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/purchase_order_line_sequence/i18n/purchase_order_line_sequence.pot b/purchase_order_line_sequence/i18n/purchase_order_line_sequence.pot index 2a884ac6306..815d120bfd0 100644 --- a/purchase_order_line_sequence/i18n/purchase_order_line_sequence.pot +++ b/purchase_order_line_sequence/i18n/purchase_order_line_sequence.pot @@ -4,10 +4,8 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" +"Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-07-10 13:13+0000\n" -"PO-Revision-Date: 2015-07-10 13:13+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -16,27 +14,38 @@ msgstr "" "Plural-Forms: \n" #. module: purchase_order_line_sequence -#: help:purchase.order.line,sequence:0 -msgid "Gives the sequence of this line when displaying the purchase order." +#: model:ir.ui.view,arch_db:purchase_order_line_sequence.report_purchase_order_sequence_qweb +#: model: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,name:purchase_order_line_sequence.model_purchase_order_line_invoice -msgid "Purchase Order Line Make Invoice" +#: 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,name:purchase_order_line_sequence.model_purchase_order_line -msgid "Purchase Order line" +#: model:ir.model,name:purchase_order_line_sequence.model_account_invoice_line +msgid "Invoice Line" +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" +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 -#: field:purchase.order.line,sequence:0 +#: model:ir.model.fields,field_description:purchase_order_line_sequence.field_purchase_order_line_sequence2 msgid "Sequence" msgstr "" From c8a58b66f67eb352327689a6ce693843bde08c61 Mon Sep 17 00:00:00 2001 From: mreficent Date: Thu, 20 Sep 2018 14:58:34 +0200 Subject: [PATCH 10/36] [FIX] Make module compatible with other reporting modules --- purchase_order_line_sequence/views/report_purchaseorder.xml | 3 ++- .../views/report_purchasequotation.xml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/purchase_order_line_sequence/views/report_purchaseorder.xml b/purchase_order_line_sequence/views/report_purchaseorder.xml index 6897229a0eb..f9f14f53f29 100644 --- a/purchase_order_line_sequence/views/report_purchaseorder.xml +++ b/purchase_order_line_sequence/views/report_purchaseorder.xml @@ -4,7 +4,8 @@ Sequence - + + diff --git a/purchase_order_line_sequence/views/report_purchasequotation.xml b/purchase_order_line_sequence/views/report_purchasequotation.xml index 319184cb69d..b5c7f710031 100644 --- a/purchase_order_line_sequence/views/report_purchasequotation.xml +++ b/purchase_order_line_sequence/views/report_purchasequotation.xml @@ -4,7 +4,8 @@ Sequence - + + From 810225583fd127fd961882119e18c13df08119e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Be=C3=B1at=20Jimenez?= Date: Mon, 26 Nov 2018 12:02:26 +0100 Subject: [PATCH 11/36] [MIG] purchase_order_line_sequence to version 12 --- purchase_order_line_sequence/README.rst | 74 ++- purchase_order_line_sequence/__init__.py | 4 - purchase_order_line_sequence/__manifest__.py | 9 +- purchase_order_line_sequence/hooks.py | 1 - .../models/__init__.py | 4 - .../models/invoice.py | 1 - .../models/purchase.py | 13 +- .../readme/CONTRIBUTORS.rst | 4 + .../readme/DESCRIPTION.rst | 3 + .../readme/ROADMAP.rst | 2 + purchase_order_line_sequence/readme/USAGE.rst | 3 + .../static/description/index.html | 440 ++++++++++++++++++ .../tests/__init__.py | 4 - .../tests/test_po_lines_sequence.py | 49 +- .../views/purchase_view.xml | 6 +- .../views/report_purchaseorder.xml | 9 +- .../views/report_purchasequotation.xml | 9 +- 17 files changed, 569 insertions(+), 66 deletions(-) create mode 100644 purchase_order_line_sequence/readme/CONTRIBUTORS.rst create mode 100644 purchase_order_line_sequence/readme/DESCRIPTION.rst create mode 100644 purchase_order_line_sequence/readme/ROADMAP.rst create mode 100644 purchase_order_line_sequence/readme/USAGE.rst create mode 100644 purchase_order_line_sequence/static/description/index.html diff --git a/purchase_order_line_sequence/README.rst b/purchase_order_line_sequence/README.rst index 6a8d140d679..e95ed1876c9 100644 --- a/purchase_order_line_sequence/README.rst +++ b/purchase_order_line_sequence/README.rst @@ -1,61 +1,93 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 - ========================================= Purchase order lines with sequence number ========================================= -Provides a new field sequence on the purchase order, which allows to manage the order of its purchase order lines. -The sequence then is propagated to the Invoice lines and the Stock Moves. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/12.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-12-0/purchase-workflow-12-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/12.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/) -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/142/10.0 +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 +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 ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* Camptocamp +* Eficent +* Serpent CS Contributors ------------- +~~~~~~~~~~~~ + * Damien Crier * Eficent Business and IT Consulting Services S.L. * Serpent Consulting Services Pvt. Ltd. -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - 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. -To contribute to this module, please visit https://odoo-community.org. +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 index 429738e8ccf..e66fb1c2ee8 100644 --- a/purchase_order_line_sequence/__init__.py +++ b/purchase_order_line_sequence/__init__.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- -# 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 . import models diff --git a/purchase_order_line_sequence/__manifest__.py b/purchase_order_line_sequence/__manifest__.py index 8fdb7fd68a8..369629a7635 100644 --- a/purchase_order_line_sequence/__manifest__.py +++ b/purchase_order_line_sequence/__manifest__.py @@ -1,22 +1,21 @@ -# -*- coding: utf-8 -*- # 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). { - 'name': 'Purchase order lines with sequence number', + 'name': 'Purchase Order Line Sequence', 'summary': 'Adds sequence to PO lines and propagates it to' 'Invoice lines and Stock Moves', - 'version': '10.0.1.0.0', + 'version': '12.0.1.0.0', 'category': 'Purchase Management', 'author': "Camptocamp, " "Eficent, " "Serpent CS, " "Odoo Community Association (OCA)", - 'website': 'http://www.camptocamp.com', + 'website': 'https://github.com/OCA/purchase-workflow', 'depends': [ - 'purchase', 'stock_picking_line_sequence', + 'purchase_stock', 'stock_picking_line_sequence', ], 'data': ['views/purchase_view.xml', 'views/report_purchaseorder.xml', diff --git a/purchase_order_line_sequence/hooks.py b/purchase_order_line_sequence/hooks.py index 51ae062f0c4..2f70060fb9a 100644 --- a/purchase_order_line_sequence/hooks.py +++ b/purchase_order_line_sequence/hooks.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # 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). diff --git a/purchase_order_line_sequence/models/__init__.py b/purchase_order_line_sequence/models/__init__.py index 8ac44a6e646..f8fdab0f427 100644 --- a/purchase_order_line_sequence/models/__init__.py +++ b/purchase_order_line_sequence/models/__init__.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- -# 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 . import purchase diff --git a/purchase_order_line_sequence/models/invoice.py b/purchase_order_line_sequence/models/invoice.py index f0159de0482..2022bd7a000 100644 --- a/purchase_order_line_sequence/models/invoice.py +++ b/purchase_order_line_sequence/models/invoice.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # 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. diff --git a/purchase_order_line_sequence/models/purchase.py b/purchase_order_line_sequence/models/purchase.py index 507221a93c6..1e96a6b11f2 100644 --- a/purchase_order_line_sequence/models/purchase.py +++ b/purchase_order_line_sequence/models/purchase.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # 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. @@ -63,19 +62,21 @@ class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' _order = 'sequence, id' - sequence = fields.Integer(help="Gives the sequence of the line when " + sequence = fields.Integer('Hidden Sequence', + help="Gives the sequence of the line when " "displaying the purchase order.", default=9999) - sequence2 = fields.Integer(help="Displays the sequence of the line in " + sequence2 = fields.Integer('Sequence', + help="Displays the sequence of the line in " "the purchase order.", related='sequence', readonly=True) @api.multi - def _create_stock_moves(self, picking): - res = super(PurchaseOrderLine, self)._create_stock_moves(picking) + def _prepare_stock_moves(self, picking): + res = super(PurchaseOrderLine, self)._prepare_stock_moves(picking) for move, line in zip(res, self): - move.write({'sequence': line.sequence}) + move.update(sequence=line.sequence) return res @api.model diff --git a/purchase_order_line_sequence/readme/CONTRIBUTORS.rst b/purchase_order_line_sequence/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..7cdefa7f0cc --- /dev/null +++ b/purchase_order_line_sequence/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ + +* Damien Crier +* Eficent Business and IT Consulting Services 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..53a02fc21ab --- /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 \ No newline at end of file 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/index.html b/purchase_order_line_sequence/static/description/index.html new file mode 100644 index 00000000000..34de3df73fc --- /dev/null +++ b/purchase_order_line_sequence/static/description/index.html @@ -0,0 +1,440 @@ + + + + + + +Purchase order lines with sequence number + + + +
+

Purchase order lines with sequence number

+ + +

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
  • +
  • Eficent
  • +
  • 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 index 06b1748392d..117ebd64788 100644 --- a/purchase_order_line_sequence/tests/__init__.py +++ b/purchase_order_line_sequence/tests/__init__.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- -# 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 . 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 index cc5a58558f4..145d09bc25b 100644 --- a/purchase_order_line_sequence/tests/test_po_lines_sequence.py +++ b/purchase_order_line_sequence/tests/test_po_lines_sequence.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # 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. @@ -15,13 +14,37 @@ def setUp(self): super(TestPurchaseOrder, self).setUp() # Useful models self.PurchaseOrder = self.env['purchase.order'] - self.Invoice = self.env['account.invoice'] self.PurchaseOrderLine = self.env['purchase.order.line'] - self.InvoiceLine = self.env['account.invoice.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.invoice'] + self.AccountInvoiceLine = self.env['account.invoice.line'] + + self.category = self.env.ref('product.product_category_1').copy( + {'name': 'Test category', 'property_valuation': 'real_time', + 'property_cost_method': 'fifo'}) + + account_type = self.env['account.account.type'].create( + {'name': 'RCV type', 'type': 'other'}) + self.account_expense = self.env['account.account'].create( + {'name': 'Expense', 'code': 'EXP00', + 'user_type_id': account_type.id, 'reconcile': True}) + self.account_payable = self.env['account.account'].create( + {'name': 'Payable', 'code': 'PAY00', + 'user_type_id': account_type.id, 'reconcile': True}) + + self.category.property_account_expense_categ_id = self.account_expense + + self.category.property_stock_account_payable_id = self.account_payable + 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, @@ -79,16 +102,18 @@ def test_invoice_sequence(self): po = self._create_purchase_order() po.button_confirm() - po.picking_ids.do_transfer() - - invoice = self.Invoice.create({'partner_id': self.partner_id.id}) - invoice.purchase_id = po.id - invoice.currency_id = self.env.ref('base.INR').id, - invoice.purchase_order_change() - + po.picking_ids.action_done() + self.invoice = self.AccountInvoice.create({ + 'partner_id': self.partner_id.id, + 'purchase_id': po.id, + 'account_id': self.partner_id.property_account_payable_id.id, + 'type': 'in_invoice', + }) + self.invoice.purchase_order_change() + self.invoice.action_invoice_open() self.assertEqual(po.order_line[0].sequence, - invoice.invoice_line_ids[0].sequence, + self.invoice.invoice_line_ids[0].sequence, 'The Sequence is not copied properly') self.assertEqual(po.order_line[1].sequence, - invoice.invoice_line_ids[1].sequence, + self.invoice.invoice_line_ids[1].sequence, 'The Sequence is not copied properly') diff --git a/purchase_order_line_sequence/views/purchase_view.xml b/purchase_order_line_sequence/views/purchase_view.xml index db8509ef9f5..48b064176e0 100644 --- a/purchase_order_line_sequence/views/purchase_view.xml +++ b/purchase_order_line_sequence/views/purchase_view.xml @@ -22,9 +22,11 @@
- {'default_sequence': max_line_sequence} + {'default_sequence': + max_line_sequence} - +
diff --git a/purchase_order_line_sequence/views/report_purchaseorder.xml b/purchase_order_line_sequence/views/report_purchaseorder.xml index f9f14f53f29..a144d414cbe 100644 --- a/purchase_order_line_sequence/views/report_purchaseorder.xml +++ b/purchase_order_line_sequence/views/report_purchaseorder.xml @@ -1,11 +1,14 @@ -