-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[11.0][IMP] sale_order_type: Find sale order type based on the products of the sale order #770
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
11f074f
[IMP] sale_order_type: Find sale order type based on the products of …
SimoRubi 89918dd
fixup! [IMP] sale_order_type: Find sale order type based on the produ…
SimoRubi 65a7dc2
[IMP] sale_order_type: Do not assign type when changing the lines, it…
SimoRubi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import sale_order_type | ||
from . import sale_order_type_rule | ||
from . import sale_order | ||
from . import res_partner | ||
from . import account_invoice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2018 Simone Rubino - Agile Business Group | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrderTypeRule(models.Model): | ||
_name = 'sale.order.type.rule' | ||
_order = 'sequence' | ||
|
||
name = fields.Char(required=True) | ||
sequence = fields.Integer(default=10) | ||
order_type_id = fields.Many2one( | ||
comodel_name='sale.order.type', ondelete='cascade') | ||
product_ids = fields.Many2many( | ||
comodel_name='product.product', | ||
string='Products') | ||
product_category_ids = fields.Many2many( | ||
comodel_name='product.category', | ||
string='Product categories') | ||
|
||
@api.multi | ||
def matches_order(self, order): | ||
"""Return True if the rule matches the order, | ||
False otherwise""" | ||
self.ensure_one() | ||
order_products = order.order_line.mapped('product_id') | ||
return self.matches_products(order_products) \ | ||
or self.matches_product_categories( | ||
order_products.mapped('categ_id')) | ||
|
||
@api.multi | ||
def matches_products(self, products): | ||
"""Return True if the rule matches any of the products, | ||
False otherwise""" | ||
self.ensure_one() | ||
return self.product_ids and any( | ||
[rule_product in products | ||
for rule_product in self.product_ids]) | ||
|
||
@api.multi | ||
def matches_product_categories(self, categories): | ||
"""Return True if the rule matches any of the categories, | ||
False otherwise""" | ||
self.ensure_one() | ||
return self.product_category_ids and any( | ||
[rule_category in categories | ||
for rule_category in self.product_category_ids]) | ||
|
||
@api.multi | ||
def matches_invoice(self, invoice): | ||
"""Return True if the rule matches the invoice, | ||
False otherwise""" | ||
self.ensure_one() | ||
invoice_products = invoice.invoice_line_ids.mapped('product_id') | ||
return self.matches_products(invoice_products) \ | ||
or self.matches_product_categories( | ||
invoice_products.mapped('categ_id')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
To configure Sale Order Types you need to: | ||
|
||
#. Go to **Sales > Configuration > Sales Orders Types** | ||
#. Create a new sale order type with all the settings you want | ||
1. Go to **Sales > Configuration > Sales Orders Types** | ||
2. Create a new sale order type with all the settings you want |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
This module adds a typology for the sales orders. In each different type, you | ||
can define, invoicing and refunding journal, a warehouse, a sequence, | ||
can define: invoicing and refunding journal, a warehouse, a sequence, | ||
the shipping policy, the invoicing policy, a payment term, a pricelist | ||
and an incoterm. | ||
|
||
You can see sale types as lines of business. | ||
|
||
You are able to select a sales order type by partner so that when you add a | ||
partner to a sales order it will get the related info to it. | ||
|
||
Rules can also be associated with sale order types. | ||
|
||
Inside each rule, you can select any number of products and/or product categories. | ||
|
||
In the sale order form you can find the matching order type by clicking on the button *Find by rule* placed near the *Type* field. | ||
If the rule does not match *by product*, product categories are checked. | ||
|
||
The sale order types and the rules are inspected based on the value of their *sequence* field. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Manage the order of *sale.order.type.rule* similar to *product.pricelist.item* (see field *applied_on*) instead of using *sequence*. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#. Go to **Sales > Sales Orders** and create a new sale order. Select the new | ||
type you have created before and all settings will be propagated. | ||
#. You can also define a type for a particular partner if you go to *Sales & | ||
Purchases* and set a sale order type. | ||
* Go to **Sales > Sales Orders** and create a new sale order. Select the new type you have created before and all settings will be propagated. | ||
* You can also define a type for a particular partner if you go to *Sales & Purchases* and set a sale order type. | ||
* You can also find the matching order type by clicking on the button *Find by rule* placed near the *Type* field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from . import test_sale_order_type | ||
from . import test_sale_order_type_rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Case 1
Product 1 -> Sale order type 1
Product 2 -> Sale order type 2
Sale Order TEST has product 1 + product 2
Which is the result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your review!
As stated few lines below, the order types are inspected following the order of their
sequence
field, so:0. Suppose Type 1 has sequence 1 and Type 2 has sequence 2;
*. Yes -> choose type 1 and exit
*. No -> go on
*. (same as above)
At least this is the behavior I tried to describe in the README, if that is not clear enough I can add an example.