Fix set_code() to don't create an extra variant on template+product creation
This commit is contained in:
parent
e2418dfa7b
commit
f85c0b7568
|
@ -2,6 +2,10 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "error:product.product:"
|
||||
msgid "The Template of the Product Variant must be unique."
|
||||
msgstr "La Plantilla a les Variants de producte ha de ser única."
|
||||
|
||||
msgctxt "field:product.template,code:"
|
||||
msgid "Code"
|
||||
msgstr "Codi"
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "error:product.product:"
|
||||
msgid "The Template of the Product Variant must be unique."
|
||||
msgstr "La Plantilla en las Variantes de producte debe ser única."
|
||||
|
||||
msgctxt "field:product.template,code:"
|
||||
msgid "Code"
|
||||
msgstr "Código"
|
||||
|
|
25
product.py
25
product.py
|
@ -1,9 +1,5 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
import logging
|
||||
from sql import Literal
|
||||
from sql.aggregate import Count
|
||||
|
||||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
|
@ -45,7 +41,7 @@ class Template:
|
|||
for template in templates:
|
||||
if template.products:
|
||||
products.append(template.products[0])
|
||||
else:
|
||||
elif value:
|
||||
new_product = Product(template=template, code=value)
|
||||
new_product.save()
|
||||
if products:
|
||||
|
@ -64,21 +60,10 @@ class Product:
|
|||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Product, cls).__setup__()
|
||||
|
||||
cursor = Transaction().cursor
|
||||
sql_table = cls.__table__()
|
||||
cursor.execute(*sql_table.select(sql_table.template, Count(Literal(1)),
|
||||
group_by=sql_table.template, having=Count(Literal(1)) > 1))
|
||||
if cursor.fetchone():
|
||||
logging.getLogger('product_variant_unique').warning(
|
||||
"There are templates with more than one variant. Please, "
|
||||
"remove these variants or split in different templates and "
|
||||
"update this module.")
|
||||
else:
|
||||
cls._sql_constraints += [
|
||||
('template_uniq', 'UNIQUE (template)',
|
||||
'The Template of the Product Variant must be unique.'),
|
||||
]
|
||||
cls._sql_constraints += [
|
||||
('template_uniq', 'UNIQUE (template)',
|
||||
'The Template of the Product Variant must be unique.'),
|
||||
]
|
||||
|
||||
|
||||
class ProductByLocation:
|
||||
|
|
Loading…
Reference in New Issue