Add module product_detailed_type and product_detailed_type_stock

This commit is contained in:
Alexis de Lattre
2023-01-20 12:02:24 +01:00
parent 1d463a744d
commit fc58a9adf5
10 changed files with 132 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
from . import models
from .post_install import set_product_detailed_type

View File

@@ -0,0 +1,19 @@
# Copyright 2023 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': 'Product Detailed Type',
'version': '14.0.1.0.0',
'category': 'Product',
'license': 'LGPL-3',
'summary': 'Backport detailed_type from v16 to v14',
'author': 'Akretion',
'website': 'https://github.com/akretion/odoo-usability',
'depends': ['product'],
'data': [
'views/product.xml',
],
'post_init_hook': 'set_product_detailed_type',
'installable': True,
}

View File

@@ -0,0 +1 @@
from . import product_template

View File

@@ -0,0 +1,25 @@
# Copyright 2023 Akretion France (http://www.akretion.com/)
# Copyright 2023 Odoo SA (contains code copy-pasted from Odoo v16)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
detailed_type = fields.Selection([
('consu', 'Consumable'),
('service', 'Service'),
], string='Product Type', default='consu', required=True, tracking=True)
type = fields.Selection(compute='_compute_type', store=True, string="Type")
def _detailed_type_mapping(self):
return {}
@api.depends('detailed_type')
def _compute_type(self):
type_mapping = self._detailed_type_mapping()
for record in self:
record.type = type_mapping.get(record.detailed_type, record.detailed_type)

View File

@@ -0,0 +1,7 @@
# Copyright 2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
def set_product_detailed_type(cr, registry):
cr.execute('UPDATE product_template SET detailed_type=type')

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2023 Akretion France (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_tree_view" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="arch" type="xml">
<field name="type" position="after">
<field name="detailed_type" optional="hide" readonly="1"/>
</field>
</field>
</record>
<record id="product_template_form_view" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<field name="type" position="after">
<field name="detailed_type"/>
</field>
<field name="type" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
<record id="product_template_search_view" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view"/>
<field name="arch" type="xml">
<filter name="type" position="attributes">
<attribute name="invisible">1</attribute>
</filter>
<filter name="type" position="after">
<filter name="detailed_type_groupby" string="Product Type" context="{'group_by': 'detailed_type'}"/>
</filter>
</field>
</record>
</odoo>

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,16 @@
# Copyright 2023 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': 'Product Detailed Type Stock',
'version': '14.0.1.0.0',
'category': 'Product',
'license': 'LGPL-3',
'summary': 'Glue module between product_detailed_type and stock',
'author': 'Akretion',
'website': 'https://github.com/akretion/odoo-usability',
'depends': ['product_detailed_type', 'stock'],
'installable': True,
'auto_install': True,
}

View File

@@ -0,0 +1 @@
from . import product_template

View File

@@ -0,0 +1,13 @@
# Copyright 2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
detailed_type = fields.Selection(selection_add=[
('product', 'Storable Product')
], ondelete={'product': 'set default'})