forked from OCA/sale-workflow
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] sale_order_type: Find sale order type based on the products of …
…the sale order (OCA#770)
- Loading branch information
1 parent
db958a0
commit bc47665
Showing
20 changed files
with
363 additions
and
31 deletions.
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
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
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 |
Oops, something went wrong.