Add module sale_layout_category_product

This commit is contained in:
Alexis de Lattre
2017-02-01 10:28:48 +01:00
parent 217afc8af0
commit c9bfc8bef2
4 changed files with 142 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import product

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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 <alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['sale'],
'data': ['product_view.xml'],
'installable': True,
}

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">add.layout_category_id.product.template.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<group name="sale" position="after">
<group name="quotes" string="Quote Layout">
<field name="layout_category_id"/>
</group>
</group>
</field>
</record>
<record id="product_category_form_view" model="ir.ui.view">
<field name="name">sale_layoutcategory.product.category.form</field>
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view"/>
<field name="arch" type="xml">
<field name="type" position="after">
<field name="layout_category_id"/>
</field>
</field>
</record>
<!-- SALE LAYOUT CATEG -->
<record id="report_configuration_form_view" model="ir.ui.view">
<field name="name">sale_layoutcategory_product.form.view</field>
<field name="model">sale.layout_category</field>
<field name="inherit_id" ref="sale.report_configuration_form_view"/>
<field name="arch" type="xml">
<xpath expr="/form/group" position="after">
<group name="product_categ" string="Product Categories">
<field name="product_categ_ids" nolabel="1"/>
</group>
<group name="product" string="Products">
<field name="product_tmpl_ids" nolabel="1"/>
</group>
</xpath>
</field>
</record>
</odoo>