Categoria de PoS por defecto por categoría de producto.
This commit is contained in:
parent
22d71e80dc
commit
ac6cb6ab95
10 changed files with 150 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,6 +3,7 @@
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
*.py~
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
@ -129,4 +130,3 @@ dmypy.json
|
||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
|
|
||||||
*~
|
|
||||||
|
|
1
product_category_default_pos_cat/__init__.py
Normal file
1
product_category_default_pos_cat/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from . import models
|
20
product_category_default_pos_cat/__manifest__.py
Normal file
20
product_category_default_pos_cat/__manifest__.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# Copyright 2021 Criptomart
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
'name': 'Product Category Default PoS Category',
|
||||||
|
'version': '12.0.1.0.0',
|
||||||
|
'author': "Criptomart",
|
||||||
|
'website': 'https://github.com/criptomart/obook',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'category': 'Product',
|
||||||
|
'depends': [
|
||||||
|
'product',
|
||||||
|
'point_of_sale'
|
||||||
|
],
|
||||||
|
'data': [
|
||||||
|
'views/product_category.xml',
|
||||||
|
'views/res_config_settings_views.xml',
|
||||||
|
],
|
||||||
|
'installable': True,
|
||||||
|
}
|
4
product_category_default_pos_cat/models/__init__.py
Normal file
4
product_category_default_pos_cat/models/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
from . import res_company
|
||||||
|
from . import res_config_settings
|
||||||
|
from . import product_product
|
||||||
|
from . import product_category
|
15
product_category_default_pos_cat/models/product_category.py
Normal file
15
product_category_default_pos_cat/models/product_category.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||||
|
# (http://www.eficent.com)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ProductCategory(models.Model):
|
||||||
|
_inherit = 'product.category'
|
||||||
|
|
||||||
|
pos_categ_id = fields.Many2one(
|
||||||
|
comodel_name="pos.category", string="Categoría en el Punto de Venta",
|
||||||
|
help="Configura los productos nuevos de ésta categoría, a la categoría del punto de venta definido aquí.",
|
||||||
|
)
|
||||||
|
|
40
product_category_default_pos_cat/models/product_product.py
Normal file
40
product_category_default_pos_cat/models/product_product.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# Copyright 2021 Criptomart
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
#import logging
|
||||||
|
|
||||||
|
from odoo import _, api, fields, models
|
||||||
|
|
||||||
|
#_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class ProductProduct(models.Model):
|
||||||
|
_inherit = 'product.product'
|
||||||
|
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def create(self, vals):
|
||||||
|
category = self.env['product.category']
|
||||||
|
categ_id = vals.get("categ_id")
|
||||||
|
template_id = vals.get("product_tmpl_id")
|
||||||
|
if categ_id:
|
||||||
|
category = category.browse(categ_id)
|
||||||
|
vals['pos_categ_id'] = self.get_category_pos_category(category)
|
||||||
|
vals['available_in_pos'] = True
|
||||||
|
elif template_id:
|
||||||
|
template = self.env["product.template"].browse(template_id)
|
||||||
|
category = template.categ_id
|
||||||
|
template.pos_categ_id = self.get_category_pos_category(category)
|
||||||
|
if template.pos_categ_id:
|
||||||
|
template.available_in_pos = True
|
||||||
|
|
||||||
|
return super().create(vals)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def get_category_pos_category(self, category=False):
|
||||||
|
cat = category
|
||||||
|
if self.env.user.company_id.use_parent_categories_to_determine_pos_categ:
|
||||||
|
while not cat.pos_categ_id and cat.parent_id:
|
||||||
|
cat = cat.parent_id
|
||||||
|
|
||||||
|
return cat.pos_categ_id
|
||||||
|
|
13
product_category_default_pos_cat/models/res_company.py
Normal file
13
product_category_default_pos_cat/models/res_company.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Copyright 2021 Criptomart
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class Company(models.Model):
|
||||||
|
_inherit = 'res.company'
|
||||||
|
|
||||||
|
use_parent_categories_to_determine_pos_categ = fields.Boolean(
|
||||||
|
string="Use parent categories to determine the pos category",
|
||||||
|
help="Use parent categories to determine the pos category if the category has no settings for the PoS category.",
|
||||||
|
)
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Copyright 2021 Criptomart
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResConfigSettings(models.TransientModel):
|
||||||
|
_inherit = 'res.config.settings'
|
||||||
|
|
||||||
|
use_parent_categories_to_determine_pos_categ = fields.Boolean(
|
||||||
|
related="company_id.use_parent_categories_to_determine_pos_categ",
|
||||||
|
readonly=False,
|
||||||
|
)
|
16
product_category_default_pos_cat/views/product_category.xml
Normal file
16
product_category_default_pos_cat/views/product_category.xml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="product_category_form_view" model="ir.ui.view">
|
||||||
|
<field name="name">product.category.form - product_category_pos_categ</field>
|
||||||
|
<field name="model">product.category</field>
|
||||||
|
<field name="inherit_id" ref="product.product_category_form_view"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="parent_id" position="after">
|
||||||
|
<field name="pos_categ_id" class="oe_inline" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
|
<odoo>
|
||||||
|
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||||
|
<field name="name">res.config.settings.view.form.inherit.product</field>
|
||||||
|
<field name="model">res.config.settings</field>
|
||||||
|
<field name="inherit_id" ref="product.res_config_settings_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<div id="product_general_settings" position="inside">
|
||||||
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
|
<div class="o_setting_left_pane">
|
||||||
|
<field name="use_parent_categories_to_determine_pos_categ" />
|
||||||
|
</div>
|
||||||
|
<div class="o_setting_right_pane">
|
||||||
|
<label for="use_parent_categories_to_determine_pos_categ"
|
||||||
|
string="Use parent categories to determine the PoS category" />
|
||||||
|
<div class="text-muted">
|
||||||
|
Use parent categories to determine the PoS category if the category
|
||||||
|
has no settings for the prefix.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
Loading…
Add table
Reference in a new issue