diff --git a/sale_layout_category_product/__init__.py b/sale_layout_category_product/__init__.py new file mode 100644 index 0000000..d7d7308 --- /dev/null +++ b/sale_layout_category_product/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import product diff --git a/sale_layout_category_product/__manifest__.py b/sale_layout_category_product/__manifest__.py new file mode 100644 index 0000000..ccea347 --- /dev/null +++ b/sale_layout_category_product/__manifest__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Sale Layout Category Product', + 'version': '10.0.1.0.0', + 'category': 'Sale Management', + 'license': 'AGPL-3', + 'summary': 'Assign a default sale layout category on products', + 'description': """ +Sale Layout Category on Products +================================ + +With this module, you can configure a default sale layout category on products (product.template). + +This module has been written by Alexis de Lattre from Akretion . + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['sale'], + 'data': ['product_view.xml'], + 'installable': True, +} diff --git a/sale_layout_category_product/product.py b/sale_layout_category_product/product.py new file mode 100644 index 0000000..eff6163 --- /dev/null +++ b/sale_layout_category_product/product.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields, api + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + layout_category_id = fields.Many2one( + 'sale.layout_category', string='Layout Category', ondelete='restrict', + help="Default section on quotations for this product. If this field " + "is empty but the equivalent field on the related product category " + "is set, it will use the layout category configured on the product " + "category") + + +class ProductProduct(models.Model): + _inherit = 'product.product' + + def get_layout_category(self): + self.ensure_one() + res = self.env['sale.layout_category'] + if self.layout_category_id: + res = self.layout_category_id + elif self.categ_id.layout_category_id: + res = self.categ_id.layout_category_id + return res + + +class ProductCategory(models.Model): + _inherit = 'product.category' + + layout_category_id = fields.Many2one( + 'sale.layout_category', string='Layout Category', + help="Default section on quotations for the products of this " + "category.") + + +class SaleLayoutCategory(models.Model): + _inherit = 'sale.layout_category' + + product_tmpl_ids = fields.One2many( + 'product.template', 'layout_category_id', + string='Products') + product_categ_ids = fields.One2many( + 'product.category', 'layout_category_id', + string='Product Categories') + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + @api.onchange('product_id') + def layout_product_id_change(self): + if self.product_id: + self.layout_category_id = self.product_id.get_layout_category() + else: + self.layout_category_id = False diff --git a/sale_layout_category_product/product_view.xml b/sale_layout_category_product/product_view.xml new file mode 100644 index 0000000..8bbf9c1 --- /dev/null +++ b/sale_layout_category_product/product_view.xml @@ -0,0 +1,53 @@ + + + + + + + add.layout_category_id.product.template.form + product.template + + + + + + + + + + + + sale_layoutcategory.product.category.form + product.category + + + + + + + + + + + + + sale_layoutcategory_product.form.view + sale.layout_category + + + + + + + + + + + + + +