Skip to content

Commit cc7b6e5

Browse files
committed
[ADD] product_kit_type: introduce kit product type with subproduct handling in SO
- Added new product type **Kit** (`is_kit`) in product form view with option to select subproducts - When a kit product is added to a Sales Order: • A button appears next to the product line to open a wizard • Wizard allows setting quantity and price for each subproduct • On save, subproduct lines are added to the SO as readonly order lines • Main kit product price is updated based on wizard values - Added option in Sales Orders to enable/disable printing of subproduct lines: • Affects customer invoice printing • Affects customer portal preview
1 parent fbf9ee9 commit cc7b6e5

15 files changed

+251
-0
lines changed

product_kit_type/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import wizard

product_kit_type/__manifest__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
'name': 'Product Type Kit',
3+
'version': '1.0',
4+
'category': 'Sales/Sales',
5+
'summary': 'Allow selecting salesperson for pos order',
6+
'depends': ['sale_management'],
7+
'installable': True,
8+
'data': [
9+
'security/ir.model.access.csv',
10+
'views/product_template_form_view.xml',
11+
'views/sale_order_views.xml',
12+
'views/sale_order_customer_preview.xml',
13+
'wizard/views/sub_products_view.xml',
14+
'report/invoice_report.xml'
15+
],
16+
'license': 'LGPL-3',
17+
}

product_kit_type/models/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import product_template
2+
from . import sale_order_line
3+
from . import sale_order
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from odoo import models, fields, api
2+
3+
4+
class InheritedProductTemplate(models.Model):
5+
_inherit = "product.template"
6+
7+
is_kit = fields.Boolean("Is kit?")
8+
sub_products = fields.Many2many("product.product", string="Sub Products")
9+
10+
@api.onchange("is_kit")
11+
def _onchange_is_kit(self):
12+
if not self.is_kit:
13+
self.sub_products = None

product_kit_type/models/sale_order.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from odoo import models, fields
2+
3+
4+
class InheritedSalesOrder(models.Model):
5+
_inherit = "sale.order"
6+
7+
print_in_report = fields.Boolean()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from odoo import models, fields
2+
3+
4+
class InheritedSalesOrderLine(models.Model):
5+
_inherit = "sale.order.line"
6+
7+
is_kit = fields.Boolean(related="product_template_id.is_kit", store=False)
8+
is_sub_product = fields.Boolean()
9+
10+
def action_sub_products(self):
11+
return {
12+
'name': f'Product: {self.name}',
13+
'view_mode': 'form',
14+
'res_model': 'product_kit_type.subproducts',
15+
'view_id': self.env.ref('product_kit_type.subproducts_view_form').id,
16+
'type': 'ir.actions.act_window',
17+
'target': 'new',
18+
}
19+
20+
def unlink(self):
21+
for line in self:
22+
if not line.is_sub_product:
23+
sale_order_line_id = line.id
24+
sub_lines = self.search([
25+
('product_id', '=', line.product_id.id),
26+
('is_sub_product', '=', True),
27+
('linked_line_id', '=', sale_order_line_id)
28+
])
29+
if sub_lines:
30+
sub_lines.unlink()
31+
return super().unlink()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
<template id="sale_order_report_inherit" inherit_id="sale.report_saleorder_document">
4+
<xpath expr="//tbody/t/tr" position="attributes">
5+
<attribute name="t-if">(doc.print_in_report) or (not line.is_sub_product)</attribute>
6+
</xpath>
7+
</template>
8+
</odoo>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_subproducts,access_product_kit_type.subproducts,product_kit_type.model_product_kit_type_subproducts,base.group_user,1,1,1,
3+
access_subproducts_lines,access_product_kit_type.subproducts.line,product_kit_type.model_product_kit_type_subproducts_line,base.group_user,1,1,1,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
<record id="product_template_form_view_inherit" model="ir.ui.view">
4+
<field name="name">product.template.form.inherit.product_type_kit</field>
5+
<field name="model">product.template</field>
6+
<field name="inherit_id" ref="product.product_template_form_view" />
7+
<field name="arch" type="xml">
8+
<xpath expr="//page[@name='general_information']//group[@name='group_general']" position="inside">
9+
<field name="is_kit" />
10+
<field name="sub_products" invisible="not is_kit" widget="many2many_tags" />
11+
</xpath>
12+
</field>
13+
</record>
14+
</odoo>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
<template id="sale_portal_templates_report_inherit" inherit_id="sale.sale_order_portal_content">
4+
<xpath expr="//table[@id='sales_order_table']/tbody/t/tr" position="attributes">
5+
<attribute name="t-if">(sale_order.print_in_report) or (not line.is_sub_product)</attribute>
6+
</xpath>
7+
</template>
8+
</odoo>
9+

0 commit comments

Comments
 (0)