Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] sale_order_priority #657

Merged
merged 4 commits into from
Jun 12, 2018
Merged

Conversation

SimoRubi
Copy link
Member

@SimoRubi SimoRubi commented Jun 6, 2018

Module to manage the priority of sale orders and link it with the generated picking.

@SimoRubi SimoRubi force-pushed the 10.0-add-sale_order_priority branch 3 times, most recently from eb86696 to 6086863 Compare June 6, 2018 14:21
Copy link
Member

@tafaRU tafaRU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor nitpicking otherwise 👍

#. 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 "Prioritdi questo ordine di vendita. Impostando qui un valore, verrà impostato anche in tutte le righe"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review, done!

@SimoRubi SimoRubi force-pushed the 10.0-add-sale_order_priority branch 2 times, most recently from ecb6563 to 7149b03 Compare June 6, 2018 15:08
@AaronHForgeFlow
Copy link
Contributor

The diff is showing changes in other modules

@SimoRubi
Copy link
Member Author

SimoRubi commented Jun 7, 2018

@aheficent I kept them in a separate commit, they fix the errors that are blocking from OCA/maintainer-quality-tools#554

@AaronHForgeFlow
Copy link
Contributor

I think it's better to say in the readme that the priority is inherited by the procurement not the picking

@SimoRubi SimoRubi force-pushed the 10.0-add-sale_order_priority branch from d98d07e to 93ad09c Compare June 7, 2018 07:51
@SimoRubi
Copy link
Member Author

SimoRubi commented Jun 7, 2018

@aheficent all in all, it's cleaner to move the fix of README errors to another PR -> #658

@SimoRubi
Copy link
Member Author

SimoRubi commented Jun 7, 2018

@aheficent fixed the README too, in order to explain the procurements' role

@SimoRubi SimoRubi force-pushed the 10.0-add-sale_order_priority branch from 93ad09c to c2a3e6a Compare June 7, 2018 08:45
Copy link
Contributor

@rousseldenis rousseldenis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models, fields, api
from odoo.addons.procurement.models import procurement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimoRubi As you depends on procurement addon, it is better to reflect it in the manifest.

@api.depends('order_line.priority')
def _compute_priority(self):
for order in self:
order.priority = order.mapped('order_line') and \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimoRubi Better to store order.mapped(...) in a variable before:

priority = order.mapped('order_line.priority')
order.priority = priority and max(priority) or '1'

_inherit = 'sale.order'

@api.depends('order_line.priority')
def _compute_priority(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for order in self:
order.order_line.write({'priority': order.priority})

priority = fields.Selection(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimoRubi Please put fields definition on top

# Copyright 2018 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models, fields, api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api, fields, models


def _inverse_priority(self):
for order in self:
order.order_line.write({'priority': order.priority})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimoRubi You cannot call write in an inverse. Affect recordset values directly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rousseldenis why can't I call write in an inverse method? I took it from https://github.com/odoo/odoo/blob/0780f10c5474ae28e768b1bbba0245b0fb46e990/addons/stock/models/stock_picking.py#L341 and tested it, it works.

Moreover I can't order.order_line = order.priority because order.order_line is One2Many

Copy link
Contributor

@rousseldenis rousseldenis Jun 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimoRubi You cannot trust everything in code but go to https://github.com/odoo/odoo/blob/0780f10c5474ae28e768b1bbba0245b0fb46e990/odoo/fields.py#L206

The problem is that inverse methods are called by write, see https://github.com/odoo/odoo/blob/0780f10c5474ae28e768b1bbba0245b0fb46e990/odoo/models.py#L3586

If you write in inverse, that can trigger some unwanted recomputations.

You have to loop into order_line and affect values.

Copy link
Member Author

@SimoRubi SimoRubi Jun 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rousseldenis now I understand what you meant, done, thanks.

Anyway, I checked that assigning directly to the model (https://github.com/odoo/odoo/blob/0780f10c5474ae28e768b1bbba0245b0fb46e990/odoo/models.py#L5238) actually seems to call the write method too (https://github.com/odoo/odoo/blob/0780f10c5474ae28e768b1bbba0245b0fb46e990/odoo/fields.py#L954), is it correct or I am mixing up already?

@AaronHForgeFlow
Copy link
Contributor

Runbot still affected by #630 cannot create a sale order line. I'll test in local later

@SimoRubi
Copy link
Member Author

SimoRubi commented Jun 7, 2018

@rousseldenis thanks for the accurate review, everything done but I have this little question

@SimoRubi
Copy link
Member Author

SimoRubi commented Jun 7, 2018

@aheficent actually runbot is green

@AaronHForgeFlow
Copy link
Contributor

@SimoRubi It is green. I meant that it is not possible to create a sale order line in runbot. Got error. But it is unrelated to this PR. See issue #630

Copy link
Contributor

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested successfully on runbot. It works.

However, can anybody explain what is the priority in the picking used for?

If I have two pickings for the same item 1 unit. Only 1 unit in stock. One picking is priority normal and the other is priority urgent. However, the first picking is already reserved, so the second picking remains waiting availability. Is there a way to automatically unreserve the first picking when confirming the second one? Thank you!

PS: I know my question refers to standard Odoo, just asking.

@rousseldenis
Copy link
Contributor

@aheficent I think it's just used in the _order property. So, procurement and picking are 'just' ordered (in tree views too). But in case of automatic assignation (scheduler or...), the picking with higher priority will reserve products before other with smaller one. In normal cases, we never see a difference because of equal values.

@AaronHForgeFlow
Copy link
Contributor

@rousseldenis all right. So confirming a SO is manual assignation. We have to manually unreserve the SO with lower priority if we need another more urgent SO to take over.

Copy link
Contributor

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@SimoRubi
Copy link
Member Author

@OCA/crm-sales-marketing-maintainers is this ok to be merged?

@yajo yajo merged commit fc3238f into OCA:10.0 Jun 12, 2018
sylvainvh pushed a commit to camptocamp/sale-workflow that referenced this pull request Feb 5, 2019
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
daramousk pushed a commit to daramousk/sale-workflow that referenced this pull request Oct 2, 2019
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
daramousk pushed a commit to daramousk/sale-workflow that referenced this pull request Nov 12, 2020
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
Tardo pushed a commit to Tecnativa/sale-workflow that referenced this pull request Feb 17, 2021
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
MiquelRForgeFlow pushed a commit to ForgeFlow/sale-workflow that referenced this pull request Feb 22, 2021
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
ThomasBinsfeld pushed a commit to acsone/sale-workflow that referenced this pull request Mar 23, 2021
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
ThomasBinsfeld pushed a commit to acsone/sale-workflow that referenced this pull request Mar 23, 2021
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
ThomasBinsfeld pushed a commit to acsone/sale-workflow that referenced this pull request Mar 23, 2021
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
ivantodorovich pushed a commit to odoo-it/sale-workflow that referenced this pull request Apr 21, 2021
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
GuillemCForgeFlow pushed a commit to ForgeFlow/sale-workflow that referenced this pull request Nov 23, 2021
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
GuillemCForgeFlow pushed a commit to ForgeFlow/sale-workflow that referenced this pull request Feb 7, 2022
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
GuillemCForgeFlow pushed a commit to ForgeFlow/sale-workflow that referenced this pull request Feb 17, 2022
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
xavier-bouquiaux pushed a commit to acsone/sale-workflow that referenced this pull request Jun 13, 2022
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
JuanyDForgeflow pushed a commit to ForgeFlow/sale-workflow that referenced this pull request Jun 28, 2022
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
pilarvargas-tecnativa pushed a commit to Tecnativa/sale-workflow that referenced this pull request Feb 7, 2023
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
astirpe pushed a commit to astirpe/sale-workflow that referenced this pull request Jul 10, 2024
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
ofelix03 pushed a commit to GlodoUK/oca_sale-workflow that referenced this pull request Sep 5, 2024
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
omalbastin pushed a commit to omalbastin/sale-workflow that referenced this pull request Nov 25, 2024
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
HeliconiaSolutions pushed a commit to HeliconiaIO/sale-workflow that referenced this pull request Dec 13, 2024
* [ADD] sale_order_priority

* Code improvements

* [FIX] Better not to call write in inverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants