From becadc7c19aa8d3ec66936c40647cb2f0502eb67 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Tue, 12 Jun 2018 16:11:36 +0200 Subject: [PATCH] [ADD] sale_order_priority (#657) * [ADD] sale_order_priority * Code improvements * [FIX] Better not to call write in inverse --- sale_order_priority/README.rst | 60 +++++++++++++++++++ sale_order_priority/__init__.py | 4 ++ sale_order_priority/__manifest__.py | 22 +++++++ sale_order_priority/i18n/it.po | 61 ++++++++++++++++++++ sale_order_priority/models/__init__.py | 4 ++ sale_order_priority/models/sale.py | 49 ++++++++++++++++ sale_order_priority/tests/__init__.py | 4 ++ sale_order_priority/tests/test_sale_stock.py | 37 ++++++++++++ sale_order_priority/views/sale.xml | 18 ++++++ 9 files changed, 259 insertions(+) create mode 100644 sale_order_priority/README.rst create mode 100644 sale_order_priority/__init__.py create mode 100644 sale_order_priority/__manifest__.py create mode 100644 sale_order_priority/i18n/it.po create mode 100644 sale_order_priority/models/__init__.py create mode 100644 sale_order_priority/models/sale.py create mode 100644 sale_order_priority/tests/__init__.py create mode 100644 sale_order_priority/tests/test_sale_stock.py create mode 100644 sale_order_priority/views/sale.xml diff --git a/sale_order_priority/README.rst b/sale_order_priority/README.rst new file mode 100644 index 000000000000..a854c88710eb --- /dev/null +++ b/sale_order_priority/README.rst @@ -0,0 +1,60 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +=================== +Sale order priority +=================== + +This module adds the field *Priority* in sale order lines and sale orders: +priority of the sale order is computed as the maximum of the priorities of its lines, +setting the priority in the order sets the priority of all its lines accordingly. + +When a picking is created as a result of sale order confirmation, +the created procurement inherits the priority of the order, +then the stock moves and the picking inherit the procurement's priority. + +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/167/10.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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Simone Rubino (www.agilebg.com) + +Do not contact contributors directly about support or help with technical issues. + +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 https://odoo-community.org. diff --git a/sale_order_priority/__init__.py b/sale_order_priority/__init__.py new file mode 100644 index 000000000000..b44d765940f6 --- /dev/null +++ b/sale_order_priority/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/sale_order_priority/__manifest__.py b/sale_order_priority/__manifest__.py new file mode 100644 index 000000000000..f7cc00849f50 --- /dev/null +++ b/sale_order_priority/__manifest__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Simone Rubino - Agile Business Group +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale order priority", + "summary": "Define priority on sale orders", + "version": "10.0.1.0.0", + "category": "Sale Workflow", + "website": "https://github.com/OCA/sale-workflow/tree/10.0/" + "sale_order_priority", + "author": "Agile Business Group, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "procurement", + "sale_stock" + ], + "data": [ + "views/sale.xml" + ] +} diff --git a/sale_order_priority/i18n/it.po b/sale_order_priority/i18n/it.po new file mode 100644 index 000000000000..124779fefc41 --- /dev/null +++ b/sale_order_priority/i18n/it.po @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_priority +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-06-06 10:42+0000\n" +"PO-Revision-Date: 2018-06-06 10:42+0000\n" +"Last-Translator: Simone Rubino \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: sale_order_priority +#: selection:sale.order,priority:0 +#: selection:sale.order.line,priority:0 +msgid "Normal" +msgstr "Normale" + +#. module: sale_order_priority +#: selection:sale.order,priority:0 +#: selection:sale.order.line,priority:0 +msgid "Not urgent" +msgstr "Non urgente" + +#. module: sale_order_priority +#: model:ir.model.fields,field_description:sale_order_priority.field_sale_order_line_priority +#: model:ir.model.fields,field_description:sale_order_priority.field_sale_order_priority +msgid "Priority" +msgstr "Priorità" + +#. module: sale_order_priority +#: model:ir.model.fields,help:sale_order_priority.field_sale_order_priority +msgid "Priority for this sale order. Setting manually a value here would set it as priority for all the order lines" +msgstr "Priorità di questo ordine di vendita. Impostando qui un valore, verrà impostato anche in tutte le righe" + +#. module: sale_order_priority +#: model:ir.model,name:sale_order_priority.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" + +#. module: sale_order_priority +#: model:ir.model,name:sale_order_priority.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga d'Ordine di Vendita" + +#. module: sale_order_priority +#: selection:sale.order,priority:0 +#: selection:sale.order.line,priority:0 +msgid "Urgent" +msgstr "Urgente" + +#. module: sale_order_priority +#: selection:sale.order,priority:0 +#: selection:sale.order.line,priority:0 +msgid "Very Urgent" +msgstr "Molto urgente" diff --git a/sale_order_priority/models/__init__.py b/sale_order_priority/models/__init__.py new file mode 100644 index 000000000000..a24563f5caa9 --- /dev/null +++ b/sale_order_priority/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import sale diff --git a/sale_order_priority/models/sale.py b/sale_order_priority/models/sale.py new file mode 100644 index 000000000000..5f9d38eefe64 --- /dev/null +++ b/sale_order_priority/models/sale.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Simone Rubino - Agile Business Group +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.addons.procurement.models import procurement + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + priority = fields.Selection( + procurement.PROCUREMENT_PRIORITIES, string='Priority', default='1') + + @api.multi + def _prepare_order_line_procurement(self, group_id=False): + self.ensure_one() + res = super(SaleOrderLine, self) \ + ._prepare_order_line_procurement(group_id=group_id) + res['priority'] = self.priority \ + or self.default_get(['priority'])['priority'] + return res + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + priority = fields.Selection( + procurement.PROCUREMENT_PRIORITIES, string='Priority', + compute='_compute_priority', inverse='_inverse_priority', store=True, + index=True, track_visibility='onchange', + states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, + help="Priority for this sale order. " + "Setting manually a value here would set it as priority " + "for all the order lines") + + @api.multi + @api.depends('order_line.priority') + def _compute_priority(self): + for order in self: + priority = order.mapped('order_line.priority') + order.priority = priority and max(priority) or '1' + + @api.multi + def _inverse_priority(self): + for order in self: + priority = order.priority + for line in order.order_line: + line.priority = priority diff --git a/sale_order_priority/tests/__init__.py b/sale_order_priority/tests/__init__.py new file mode 100644 index 000000000000..113c1f054e2d --- /dev/null +++ b/sale_order_priority/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_sale_stock diff --git a/sale_order_priority/tests/test_sale_stock.py b/sale_order_priority/tests/test_sale_stock.py new file mode 100644 index 000000000000..2a69378b8b3b --- /dev/null +++ b/sale_order_priority/tests/test_sale_stock.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Simone Rubino - Agile Business Group +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.addons.sale.tests.test_sale_common import TestSale + + +class TestSaleStock(TestSale): + + def test_sale_order_priority(self): + sale_order_priority = '3' + self.sale_order = self.env['sale.order'].create({ + 'partner_id': self.partner.id, + 'priority': sale_order_priority, + 'order_line': [(0, 0, { + 'name': p.name, + 'product_id': p.id, + 'product_uom_qty': 2, + 'product_uom': p.uom_id.id, + 'price_unit': p.list_price}) + for (_, p) in self.products.iteritems()], + }) + sale_order_line_priority = '2' + for sol in self.sale_order.order_line: + # Test that the order's priority has been + # correctly assigned to the order lines + self.assertEqual( + sol.priority, sale_order_priority, + 'Priority of order lines does not match') + sol.priority = sale_order_line_priority + # Confirm the order and check the picking + self.sale_order.action_confirm() + # Test that the lines' priority has been + # correctly assigned to the generated pickings + self.assertEqual( + max(self.sale_order.picking_ids.mapped('priority')), + sale_order_line_priority, + 'Priority of generated picking does not match') diff --git a/sale_order_priority/views/sale.xml b/sale_order_priority/views/sale.xml new file mode 100644 index 000000000000..b984bc6aa39b --- /dev/null +++ b/sale_order_priority/views/sale.xml @@ -0,0 +1,18 @@ + + + + + Sale order priority + sale.order + + + + + + + + + + +