From 11f074f6e06b60bc8d93b44659ef1872161156a0 Mon Sep 17 00:00:00 2001 From: SimoRubi Date: Tue, 16 Oct 2018 13:52:59 +0200 Subject: [PATCH 1/3] [IMP] sale_order_type: Find sale order type based on the products of the sale order --- sale_order_type/README.rst | 30 +++- sale_order_type/__manifest__.py | 1 + sale_order_type/models/__init__.py | 1 + sale_order_type/models/account_invoice.py | 12 +- sale_order_type/models/sale_order.py | 17 +++ sale_order_type/models/sale_order_type.py | 15 ++ .../models/sale_order_type_rule.py | 59 ++++++++ sale_order_type/readme/CONFIGURE.rst | 4 +- sale_order_type/readme/CONTRIBUTORS.rst | 1 + sale_order_type/readme/DESCRIPTION.rst | 13 +- sale_order_type/readme/ROADMAP.rst | 1 + sale_order_type/readme/USAGE.rst | 7 +- sale_order_type/security/ir.model.access.csv | 3 + sale_order_type/static/description/index.html | 47 +++--- sale_order_type/tests/__init__.py | 1 + sale_order_type/tests/test_sale_order_type.py | 2 +- .../tests/test_sale_order_type_rule.py | 143 ++++++++++++++++++ .../views/account_invoice_view.xml | 10 +- .../views/sale_order_type_rule_view.xml | 32 ++++ .../views/sale_order_type_view.xml | 6 + sale_order_type/views/sale_order_view.xml | 7 +- 21 files changed, 377 insertions(+), 35 deletions(-) create mode 100644 sale_order_type/models/sale_order_type_rule.py create mode 100644 sale_order_type/readme/ROADMAP.rst create mode 100644 sale_order_type/tests/test_sale_order_type_rule.py create mode 100644 sale_order_type/views/sale_order_type_rule_view.xml diff --git a/sale_order_type/README.rst b/sale_order_type/README.rst index b381b3ef3cf..f31c747ffdb 100644 --- a/sale_order_type/README.rst +++ b/sale_order_type/README.rst @@ -26,7 +26,7 @@ Sale Order Type |badge1| |badge2| |badge3| |badge4| |badge5| 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. @@ -35,6 +35,17 @@ 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. + **Table of contents** .. contents:: @@ -45,16 +56,20 @@ Configuration 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 Usage ===== -#. 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 + +Known issues / Roadmap +====================== + +* Manage the order of *sale.order.type.rule* similar to *product.pricelist.item* (see field *applied_on*) instead of using *sequence*. Bug Tracker =========== @@ -95,6 +110,7 @@ Contributors * `Agile Business Group `_ * Lorenzo Battistini + * Simone Rubino * `Niboo `_ diff --git a/sale_order_type/__manifest__.py b/sale_order_type/__manifest__.py index 4302b346e8c..25f899420d0 100644 --- a/sale_order_type/__manifest__.py +++ b/sale_order_type/__manifest__.py @@ -31,6 +31,7 @@ "security/security.xml", "views/sale_order_view.xml", "views/sale_order_type_view.xml", + "views/sale_order_type_rule_view.xml", "views/account_invoice_view.xml", "views/res_partner_view.xml", "data/default_type.xml", diff --git a/sale_order_type/models/__init__.py b/sale_order_type/models/__init__.py index c16a1913069..fc920329f4f 100644 --- a/sale_order_type/models/__init__.py +++ b/sale_order_type/models/__init__.py @@ -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 diff --git a/sale_order_type/models/account_invoice.py b/sale_order_type/models/account_invoice.py index d4e941b7151..101e15440e6 100644 --- a/sale_order_type/models/account_invoice.py +++ b/sale_order_type/models/account_invoice.py @@ -24,6 +24,16 @@ def _onchange_partner_id(self): @api.onchange('sale_type_id') def onchange_sale_type_id(self): if self.sale_type_id.payment_term_id: - self.payment_term = self.sale_type_id.payment_term_id.id + self.payment_term_id = self.sale_type_id.payment_term_id.id if self.sale_type_id.journal_id: self.journal_id = self.sale_type_id.journal_id.id + + @api.multi + def match_order_type(self): + order_types = self.env['sale.order.type'].search([]) + for invoice in self: + for order_type in order_types: + if order_type.matches_invoice(invoice): + invoice.sale_type_id = order_type + invoice.onchange_sale_type_id() + break diff --git a/sale_order_type/models/sale_order.py b/sale_order_type/models/sale_order.py index 2a5551778a5..6ec96baa744 100644 --- a/sale_order_type/models/sale_order.py +++ b/sale_order_type/models/sale_order.py @@ -36,6 +36,23 @@ def onchange_type_id(self): if order.type_id.incoterm_id: order.incoterm = order.type_id.incoterm_id.id + @api.multi + @api.onchange('order_line') + def _onchange_order_line(self): + for order in self: + if not order.type_id: + order.match_order_type() + + @api.multi + def match_order_type(self): + order_types = self.env['sale.order.type'].search([]) + for order in self: + for order_type in order_types: + if order_type.matches_order(order): + order.type_id = order_type + order.onchange_type_id() + break + @api.model def create(self, vals): if vals.get('name', '/') == '/'and vals.get('type_id'): diff --git a/sale_order_type/models/sale_order_type.py b/sale_order_type/models/sale_order_type.py index f3161d37656..1fd64d9000d 100644 --- a/sale_order_type/models/sale_order_type.py +++ b/sale_order_type/models/sale_order_type.py @@ -6,6 +6,7 @@ class SaleOrderTypology(models.Model): _name = 'sale.order.type' _description = 'Type of sale order' + _order = 'sequence' @api.model def _get_domain_sequence_id(self): @@ -40,3 +41,17 @@ def default_picking_policy(self): payment_term_id = fields.Many2one('account.payment.term', 'Payment Term') pricelist_id = fields.Many2one('product.pricelist', 'Pricelist') incoterm_id = fields.Many2one('stock.incoterms', 'Incoterm') + sequence = fields.Integer(default=10) + rule_ids = fields.One2many( + comodel_name='sale.order.type.rule', inverse_name='order_type_id', + copy=True) + + @api.multi + def matches_order(self, order): + self.ensure_one() + return any(rule.matches_order(order) for rule in self.rule_ids) + + @api.multi + def matches_invoice(self, invoice): + self.ensure_one() + return any(rule.matches_invoice(invoice) for rule in self.rule_ids) diff --git a/sale_order_type/models/sale_order_type_rule.py b/sale_order_type/models/sale_order_type_rule.py new file mode 100644 index 00000000000..1e4b00a1dee --- /dev/null +++ b/sale_order_type/models/sale_order_type_rule.py @@ -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')) diff --git a/sale_order_type/readme/CONFIGURE.rst b/sale_order_type/readme/CONFIGURE.rst index bda7917a2ca..97b86c1dcef 100644 --- a/sale_order_type/readme/CONFIGURE.rst +++ b/sale_order_type/readme/CONFIGURE.rst @@ -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 diff --git a/sale_order_type/readme/CONTRIBUTORS.rst b/sale_order_type/readme/CONTRIBUTORS.rst index 90814428dc6..e12ce4e155b 100644 --- a/sale_order_type/readme/CONTRIBUTORS.rst +++ b/sale_order_type/readme/CONTRIBUTORS.rst @@ -12,6 +12,7 @@ * `Agile Business Group `_ * Lorenzo Battistini + * Simone Rubino * `Niboo `_ diff --git a/sale_order_type/readme/DESCRIPTION.rst b/sale_order_type/readme/DESCRIPTION.rst index a70f452c490..646500a7c54 100644 --- a/sale_order_type/readme/DESCRIPTION.rst +++ b/sale_order_type/readme/DESCRIPTION.rst @@ -1,5 +1,5 @@ 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. @@ -7,3 +7,14 @@ 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. diff --git a/sale_order_type/readme/ROADMAP.rst b/sale_order_type/readme/ROADMAP.rst new file mode 100644 index 00000000000..7a9006c8a20 --- /dev/null +++ b/sale_order_type/readme/ROADMAP.rst @@ -0,0 +1 @@ +* Manage the order of *sale.order.type.rule* similar to *product.pricelist.item* (see field *applied_on*) instead of using *sequence*. diff --git a/sale_order_type/readme/USAGE.rst b/sale_order_type/readme/USAGE.rst index 1b9916402e9..ceb8431599c 100644 --- a/sale_order_type/readme/USAGE.rst +++ b/sale_order_type/readme/USAGE.rst @@ -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 diff --git a/sale_order_type/security/ir.model.access.csv b/sale_order_type/security/ir.model.access.csv index 864a1e29585..336a821c0a6 100644 --- a/sale_order_type/security/ir.model.access.csv +++ b/sale_order_type/security/ir.model.access.csv @@ -2,3 +2,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_sale_order_type_manager,access_sale_order_type_manager,model_sale_order_type,sales_team.group_sale_manager,1,1,1,1 access_sale_order_type_salesman,access_sale_order_type_salesman,model_sale_order_type,sales_team.group_sale_salesman,1,0,0,0 access_sale_order_type_account,access_sale_order_type_account,model_sale_order_type,account.group_account_invoice,1,0,0,0 +access_sale_order_type_rule_manager,access_sale_order_type_rule_manager,model_sale_order_type_rule,sales_team.group_sale_manager,1,1,1,1 +access_sale_order_type_rule_salesman,access_sale_order_type_rule_salesman,model_sale_order_type_rule,sales_team.group_sale_salesman,1,0,0,0 +access_sale_order_type_rule_account,access_sale_order_type_rule_account,model_sale_order_type_rule,account.group_account_invoice,1,0,0,0 diff --git a/sale_order_type/static/description/index.html b/sale_order_type/static/description/index.html index 7eba505c22b..c897b008632 100644 --- a/sale_order_type/static/description/index.html +++ b/sale_order_type/static/description/index.html @@ -369,22 +369,29 @@

Sale Order Type

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runbot

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.

+

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.

Table of contents

Usage

-
    -
  1. 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.
  2. -
  3. You can also define a type for a particular partner if you go to Sales & -Purchases and set a sale order type.
  4. -
+
    +
  • 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
  • +
+
+
+

Known issues / Roadmap

+
    +
  • Manage the order of sale.order.type.rule similar to product.pricelist.item (see field applied_on) instead of using sequence.
  • +
-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed @@ -415,9 +427,9 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Grupo Vermon
  • AvanzOSC
  • @@ -427,7 +439,7 @@

    Authors

-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose diff --git a/sale_order_type/tests/__init__.py b/sale_order_type/tests/__init__.py index a6456dd2adf..ede627f59c3 100644 --- a/sale_order_type/tests/__init__.py +++ b/sale_order_type/tests/__init__.py @@ -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 diff --git a/sale_order_type/tests/test_sale_order_type.py b/sale_order_type/tests/test_sale_order_type.py index 6924ebe1c82..b59207d6cd0 100644 --- a/sale_order_type/tests/test_sale_order_type.py +++ b/sale_order_type/tests/test_sale_order_type.py @@ -86,7 +86,7 @@ def test_invoice_onchange_type(self): sale_type = self.sale_type invoice = self.invoice_model.new({'sale_type_id': sale_type.id}) invoice.onchange_sale_type_id() - self.assertTrue(invoice.payment_term == sale_type.payment_term_id.id) + self.assertTrue(invoice.payment_term_id == sale_type.payment_term_id) self.assertTrue(invoice.journal_id == sale_type.journal_id) def test_invoice_onchange_partner(self): diff --git a/sale_order_type/tests/test_sale_order_type_rule.py b/sale_order_type/tests/test_sale_order_type_rule.py new file mode 100644 index 00000000000..7e0e23a7d87 --- /dev/null +++ b/sale_order_type/tests/test_sale_order_type_rule.py @@ -0,0 +1,143 @@ +# -*- 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.tests import common + + +class TestSaleOrderTypeRule(common.TransactionCase): + + def setUp(self): + super(TestSaleOrderTypeRule, self).setUp() + self.invoice_model = self.env['account.invoice'] + self.sale_order_model = self.env['sale.order'] + self.sale_type_model = self.env['sale.order.type'] + self.sale_type_rule_model = self.env['sale.order.type.rule'] + self.product_model = self.env['product.product'] + + self.account = self.env.ref('l10n_generic_coa.1_conf_a_recv') + self.partner = self.env.ref('base.res_partner_1') + self.product1, self.product2 = self.product_model.search([], limit=2) + self.product_category = self.product2.categ_id + + self.sale_type_prod = self.create_sale_type('Product') + self.sale_type_prod.write({'rule_ids': [(0, 0, { + 'name': 'Product', + 'product_ids': [(4, self.product1.id)]})]}) + + self.sale_type_categ = self.create_sale_type('Category') + self.sale_type_categ.write({'rule_ids': [(0, 0, { + 'name': 'Category', + 'product_category_ids': [(4, self.product_category.id)]})]}) + + def create_sale_type(self, name): + self.sequence = self.env['ir.sequence'].create({ + 'name': 'Test Sales Order', + 'code': 'sale.order', + 'prefix': 'TSO', + 'padding': 3, + }) + self.journal = self.env['account.journal'].search( + [('type', '=', 'sale')], limit=1) + self.warehouse = self.env.ref('stock.stock_warehouse_shop0') + self.immediate_payment = self.env.ref( + 'account.account_payment_term_immediate') + self.sale_pricelist = self.env.ref('product.list0') + self.free_carrier = self.env.ref('stock.incoterm_FCA') + return self.sale_type_model.create({ + 'name': name, + 'sequence_id': self.sequence.id, + 'journal_id': self.journal.id, + 'warehouse_id': self.warehouse.id, + 'picking_policy': 'one', + 'payment_term_id': self.immediate_payment.id, + 'pricelist_id': self.sale_pricelist.id, + 'incoterm_id': self.free_carrier.id + }) + + def prepare_sale_order_vals(self, product_ids): + sale_line_vals_list = list(dict()) + for product_id in product_ids: + sale_line_vals_list.append({ + 'product_id': product_id.id, + 'name': product_id.name, + 'product_uom_qty': 1.0, + 'price_unit': product_id.lst_price, + }) + return { + 'partner_id': self.partner.id, + 'order_line': [(0, 0, sale_line_vals) + for sale_line_vals in sale_line_vals_list] + } + + def prepare_invoice_vals(self, product_ids): + invoice_line_vals_list = list(dict()) + for product_id in product_ids: + invoice_line_vals_list.append({ + 'account_id': self.account.id, + 'product_id': product_id.id, + 'name': product_id.name, + 'product_uom_qty': 1.0, + 'price_unit': product_id.lst_price, + }) + return { + 'account_id': self.account.id, + 'partner_id': self.partner.id, + 'invoice_line_ids': [ + (0, 0, invoice_line_vals) + for invoice_line_vals in invoice_line_vals_list] + } + + def test_sale_match_product(self): + sale_order_vals = self.prepare_sale_order_vals(self.product1) + sale_order = self.sale_order_model.create(sale_order_vals) + + sale_order.match_order_type() + + self.assertEqual(sale_order.type_id, self.sale_type_prod) + + def test_sale_match_category(self): + sale_order_vals = self.prepare_sale_order_vals(self.product2) + sale_order = self.sale_order_model.create(sale_order_vals) + + sale_order.match_order_type() + + self.assertEqual(sale_order.type_id, self.sale_type_categ) + + def test_sale_match_product_category(self): + """ If a sale order has both product and category matching, + choose the rule having the product.""" + sale_order_vals = self.prepare_sale_order_vals( + self.product1 + self.product2) + sale_order = self.sale_order_model.create(sale_order_vals) + + sale_order.match_order_type() + + self.assertEqual(sale_order.type_id, self.sale_type_prod) + + def test_invoice_match_product(self): + invoice_vals = self.prepare_invoice_vals(self.product1) + invoice = self.invoice_model.create(invoice_vals) + + invoice.match_order_type() + + self.assertEqual(invoice.sale_type_id, self.sale_type_prod) + + def test_invoice_match_category(self): + invoice_vals = self.prepare_invoice_vals(self.product2) + invoice = self.invoice_model.create(invoice_vals) + + invoice.match_order_type() + + self.assertEqual(invoice.sale_type_id, self.sale_type_categ) + + def test_invoice_match_product_category(self): + """ If a sale order has both product and category matching, + choose the rule having the product.""" + invoice_vals = self.prepare_invoice_vals( + self.product1 + self.product2) + invoice = self.invoice_model.create(invoice_vals) + + invoice.match_order_type() + + self.assertEqual(invoice.sale_type_id, self.sale_type_prod) diff --git a/sale_order_type/views/account_invoice_view.xml b/sale_order_type/views/account_invoice_view.xml index e4679f23b5d..4694f970612 100644 --- a/sale_order_type/views/account_invoice_view.xml +++ b/sale_order_type/views/account_invoice_view.xml @@ -6,7 +6,15 @@ - +

+ +
diff --git a/sale_order_type/views/sale_order_type_rule_view.xml b/sale_order_type/views/sale_order_type_rule_view.xml new file mode 100644 index 00000000000..87dc638fe6a --- /dev/null +++ b/sale_order_type/views/sale_order_type_rule_view.xml @@ -0,0 +1,32 @@ + + + + + + Sale order type rule form + sale.order.type.rule + +
+ + + + + + + +
+
+
+ + + Sale order type rule tree + sale.order.type.rule + + + + + + + +
diff --git a/sale_order_type/views/sale_order_type_view.xml b/sale_order_type/views/sale_order_type_view.xml index 101018de739..79ed6b0f0c1 100644 --- a/sale_order_type/views/sale_order_type_view.xml +++ b/sale_order_type/views/sale_order_type_view.xml @@ -31,6 +31,11 @@ + + + + + @@ -41,6 +46,7 @@ sale.order.type + diff --git a/sale_order_type/views/sale_order_view.xml b/sale_order_type/views/sale_order_view.xml index a09f2a7f6a2..b4ff0176371 100644 --- a/sale_order_type/views/sale_order_view.xml +++ b/sale_order_type/views/sale_order_view.xml @@ -6,7 +6,12 @@ - + From 89918ddf3e74c194e2788d305df6f98f73e44941 Mon Sep 17 00:00:00 2001 From: SimoRubi Date: Fri, 21 Dec 2018 15:54:44 +0100 Subject: [PATCH 2/3] fixup! [IMP] sale_order_type: Find sale order type based on the products of the sale order --- sale_order_type/__manifest__.py | 2 +- sale_order_type/models/sale_order_type_rule.py | 1 - sale_order_type/tests/test_sale_order_type_rule.py | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/sale_order_type/__manifest__.py b/sale_order_type/__manifest__.py index 25f899420d0..08dade8e4d6 100644 --- a/sale_order_type/__manifest__.py +++ b/sale_order_type/__manifest__.py @@ -8,7 +8,7 @@ { "name": "Sale Order Type", - "version": "11.0.1.3.0", + "version": "11.0.1.4.0", "category": "Sales Management", "author": "Grupo Vermon," "AvanzOSC," diff --git a/sale_order_type/models/sale_order_type_rule.py b/sale_order_type/models/sale_order_type_rule.py index 1e4b00a1dee..86c30cb011d 100644 --- a/sale_order_type/models/sale_order_type_rule.py +++ b/sale_order_type/models/sale_order_type_rule.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2018 Simone Rubino - Agile Business Group # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/sale_order_type/tests/test_sale_order_type_rule.py b/sale_order_type/tests/test_sale_order_type_rule.py index 7e0e23a7d87..9d7a7dba133 100644 --- a/sale_order_type/tests/test_sale_order_type_rule.py +++ b/sale_order_type/tests/test_sale_order_type_rule.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2018 Simone Rubino - Agile Business Group # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). From 65a7dc240c43f0426b00431a48e3c75e8361c0e1 Mon Sep 17 00:00:00 2001 From: SimoRubi Date: Fri, 1 Feb 2019 12:37:33 +0100 Subject: [PATCH 3/3] [IMP] sale_order_type: Do not assign type when changing the lines, it can be confusing and not efficient. --- sale_order_type/README.rst | 4 +--- sale_order_type/models/sale_order.py | 7 ------- sale_order_type/readme/DESCRIPTION.rst | 4 +--- sale_order_type/static/description/index.html | 3 +-- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/sale_order_type/README.rst b/sale_order_type/README.rst index f31c747ffdb..929ba25b936 100644 --- a/sale_order_type/README.rst +++ b/sale_order_type/README.rst @@ -39,11 +39,9 @@ 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. +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. -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. **Table of contents** diff --git a/sale_order_type/models/sale_order.py b/sale_order_type/models/sale_order.py index 6ec96baa744..923208315cc 100644 --- a/sale_order_type/models/sale_order.py +++ b/sale_order_type/models/sale_order.py @@ -36,13 +36,6 @@ def onchange_type_id(self): if order.type_id.incoterm_id: order.incoterm = order.type_id.incoterm_id.id - @api.multi - @api.onchange('order_line') - def _onchange_order_line(self): - for order in self: - if not order.type_id: - order.match_order_type() - @api.multi def match_order_type(self): order_types = self.env['sale.order.type'].search([]) diff --git a/sale_order_type/readme/DESCRIPTION.rst b/sale_order_type/readme/DESCRIPTION.rst index 646500a7c54..5619b6f12b5 100644 --- a/sale_order_type/readme/DESCRIPTION.rst +++ b/sale_order_type/readme/DESCRIPTION.rst @@ -12,9 +12,7 @@ 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. +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. -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. diff --git a/sale_order_type/static/description/index.html b/sale_order_type/static/description/index.html index c897b008632..9aa37ee8b79 100644 --- a/sale_order_type/static/description/index.html +++ b/sale_order_type/static/description/index.html @@ -377,9 +377,8 @@

Sale Order Type

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. +

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.

-

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.

Table of contents