al crear productos, setea la categoria del ecommerce según la categoría interna
This commit is contained in:
parent
a26a8e2c32
commit
27f0791503
9 changed files with 152 additions and 0 deletions
1
product_category_default_ecommerce_cat/__init__.py
Normal file
1
product_category_default_ecommerce_cat/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import models
|
||||
21
product_category_default_ecommerce_cat/__manifest__.py
Normal file
21
product_category_default_ecommerce_cat/__manifest__.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Copyright 2022 Criptomart
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Product Category Default e-commerce Category',
|
||||
'summary': "Set up default public categories based in internal category.",
|
||||
'version': '12.0.1.0.0',
|
||||
'author': "Criptomart",
|
||||
'website': 'https://criptomart.net',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'Product',
|
||||
'depends': [
|
||||
'product',
|
||||
'website_sale'
|
||||
],
|
||||
'data': [
|
||||
'views/product_category.xml',
|
||||
'views/res_config_settings_views.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
from . import res_company
|
||||
from . import res_config_settings
|
||||
from . import product_product
|
||||
from . import product_category
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ProductCategory(models.Model):
|
||||
_inherit = 'product.category'
|
||||
|
||||
public_categ_id = fields.Many2one(
|
||||
comodel_name="product.public.category", string="Categoría en la tienda online",
|
||||
help="Configura los productos nuevos en ésta categoría interna, a la categoría de la tienda online definido aquí.",
|
||||
)
|
||||
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
#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):
|
||||
categ_id = vals.get("categ_id")
|
||||
template_id = vals.get("product_tmpl_id")
|
||||
if categ_id:
|
||||
#check if there are public categories setup by user
|
||||
new_cats = []
|
||||
old_cats = vals.get("public_categ_ids")
|
||||
if old_cats[0][2]:
|
||||
for i in old_cats[0][2]:
|
||||
new_cats.append(i)
|
||||
category = self.env['product.category'].browse(categ_id)
|
||||
pub_cat = self.get_category_public_category(category).id
|
||||
if pub_cat:
|
||||
new_cats.append(pub_cat)
|
||||
vals['public_categ_ids'] = [[6,0,new_cats]]
|
||||
#vals['is_published'] = True
|
||||
elif template_id:
|
||||
template = self.env["product.template"].browse(template_id)
|
||||
category = template.categ_id
|
||||
pub_cat = self.get_category_public_category(category)
|
||||
if pub_cat:
|
||||
template.public_categ_ids += pub_cat
|
||||
# autopublish
|
||||
#if template.public_categ_id:
|
||||
# template.is_published = True
|
||||
|
||||
return super().create(vals)
|
||||
|
||||
@api.model
|
||||
def get_category_public_category(self, category=False):
|
||||
cat = category
|
||||
if not cat.public_categ_id and self.env.user.company_id.use_parent_categories_to_determine_public_cat:
|
||||
while not cat.public_categ_id and cat.parent_id:
|
||||
cat = cat.parent_id
|
||||
return cat.public_categ_id
|
||||
13
product_category_default_ecommerce_cat/models/res_company.py
Normal file
13
product_category_default_ecommerce_cat/models/res_company.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Copyright 2022 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_public_cat = fields.Boolean(
|
||||
string="Use parent categories to determine the ecommerce category",
|
||||
help="Use parent categories if the category has no set up the public category.",
|
||||
)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# Copyright 2022 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_public_cat = fields.Boolean(
|
||||
related="company_id.use_parent_categories_to_determine_public_cat",
|
||||
readonly=False,
|
||||
)
|
||||
|
|
@ -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_public_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="public_categ_id" class="oe_inline" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<odoo>
|
||||
|
||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">res.config.settings.view.form.inherit.product.public.cat</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_public_cat" />
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="use_parent_categories_to_determine_public_cat"
|
||||
string="Use parent categories to determine the public category" />
|
||||
<div class="text-muted">
|
||||
Use parent categories to determine the e-commerce category, if the e-commerce category
|
||||
has not been set up.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue