Skip to content

Commit

Permalink
[ADD] sale_order_priority (OCA#657)
Browse files Browse the repository at this point in the history
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
  • Loading branch information
SimoRubi authored and ofelix03 committed Sep 5, 2024
1 parent d594f68 commit 1c90559
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 0 deletions.
60 changes: 60 additions & 0 deletions sale_order_priority/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/OCA/sale-workflow/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Simone Rubino <simone.rubino@agilebg.com> (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.
4 changes: 4 additions & 0 deletions sale_order_priority/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
22 changes: 22 additions & 0 deletions sale_order_priority/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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"
]
}
61 changes: 61 additions & 0 deletions sale_order_priority/i18n/it.po
Original file line number Diff line number Diff line change
@@ -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 <simone.rubino@agilebg.com>\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"
4 changes: 4 additions & 0 deletions sale_order_priority/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import sale
49 changes: 49 additions & 0 deletions sale_order_priority/models/sale.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions sale_order_priority/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import test_sale_stock
37 changes: 37 additions & 0 deletions sale_order_priority/tests/test_sale_stock.py
Original file line number Diff line number Diff line change
@@ -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')
18 changes: 18 additions & 0 deletions sale_order_priority/views/sale.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Simone Rubino - Agile Business Group
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="name">Sale order priority</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<group name="sales_person" position="inside">
<field name="priority"/>
</group>
<xpath expr="//field[@name='order_line']//form//field[@name='price_unit']" position="after">
<field name="priority"/>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 1c90559

Please sign in to comment.