-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
- Loading branch information
Showing
20 changed files
with
870 additions
and
26 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,59 @@ | ||
# -*- coding: utf-8 -*- | ||
# 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
To configure Sale Order Types you need to: | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
* Carlos Sánchez Cifuentes <csanchez@grupovermon.com> | ||
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es> | ||
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> | ||
* Ana Juaristi <anajuaristi@avanzosc.es> | ||
* Daniel Campos <danielcampos@avanzosc.es> | ||
* Ainara Galdona <ainaragaldona@avanzosc.es> | ||
* Lorenzo Battistini <lorenzo.battistini@agilebg.com> | ||
* Samuel Lefever <sam@niboo.be> | ||
* Pierre Faniel <pierre@niboo.be> | ||
* Simone Rubino <simone.rubino@agilebg.com> |
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,20 @@ | ||
This module adds a typology for the sales orders. In each different type, you | ||
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. | ||
|
||
When editing a sale order that has no type, if a product matches the product of any rule then the sale order type bound to the rule is associated to the sale order. | ||
If the rule does not match *by product*, product categories are checked. | ||
|
||
In the sale order form you can also find the matching order type by clicking on the button *Find by rule* placed near the *Type* field. | ||
|
||
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,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. | ||
* 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
Oops, something went wrong.