[ADD][T4541] New configs

Merged Hermes requested to merge T4541 into 12.0
Compare and
2 files
+ 47
68
Preferences
File browser
Compare changes
@@ -20,9 +20,7 @@ class CustomerPurchaseOrderConfig(models.Model):
_description = 'Customer Purchase Order Configuration'
name = fields.Char()
partner = fields.Many2one(
'res.partner', on_delete='cascade', string='Company', required=True
)
partner = fields.Many2one('res.partner', on_delete='cascade', string='Company', required=True)
product_type = fields.Many2one('product.type', string='Product Type')
customer_po_config_line_ids = fields.One2many(
comodel_name='customer.purchase.order.config.line',
@@ -32,7 +30,9 @@ class CustomerPurchaseOrderConfig(models.Model):
config_type = fields.Selection(
(
('boxes_based_on_units', 'Boxes Based on Units'),
('boxes_in_kg', 'Boxes in Kg'),
('custom_uom', 'Custom UoM'),
('gross_price_by_units', 'Gross Price by Units'),
('internal_code', 'Internal Code'),
('item_gross_price', 'Item Gross Price'),
('ordered_qty', 'Ordered Quantity'),
@@ -54,11 +54,12 @@ class CustomerPurchaseOrderConfig(models.Model):
if self.config_type == 'boxes_based_on_units':
msg = _('Box Quantity = Ordered Quantity / Units per Box')
elif self.config_type == 'boxes_in_kg':
msg = _('Box Quantity = Ordered Quantity / Box Kilograms')
elif self.config_type == 'custom_uom':
msg = _(
'If file\'s product UoM is \'PZA: Box Quantity = Box Quantity '
'/ Units per Box.'
)
msg = _("If file's product UoM is 'PZA: Box Quantity = Box Quantity " '/ Units per Box.')
elif self.config_type == 'gross_price_by_units':
msg = _('Gross Price = Gross Price / Units per Box')
elif self.config_type == 'item_gross_price':
msg = _('Item Gross Price = Item Gross Price / Box Quantity')
elif self.config_type == 'internal_code':
@@ -67,36 +68,28 @@ class CustomerPurchaseOrderConfig(models.Model):
'for the products so as to import them from the file.'
)
elif self.config_type == 'maxipiece':
msg = _(
'If the product is a \'Maxipiece\': Box Quantity = Ordered '
'Quantity / Box Kilograms.'
)
msg = _("If the product is a 'Maxipiece': Box Quantity = Ordered " 'Quantity / Box Kilograms.')
elif self.config_type == 'ordered_qty':
msg = _(
'If product UoM is \'Kg\': Box Quantity = Ordered Quantity / '
"If product UoM is 'Kg': Box Quantity = Ordered Quantity / "
'Box Kilograms, else: Box Quantity = Ordered Quantity,'
)
elif self.config_type == 'ordered_qty_for_kg':
msg = _(
'If product UoM is \'Kg\': Box Quantity = Ordered Quantity / '
'Box Kilograms.'
)
msg = _("If product UoM is 'Kg': Box Quantity = Ordered Quantity / " 'Box Kilograms.')
elif self.config_type == 'product_uom':
msg = _(
'If product UoM is \'Units\': Box Quantity = Box Quantity / '
'Units per Box. If product UoM is \'Kg\': Box Quantity = '
"If product UoM is 'Units': Box Quantity = Box Quantity / "
"Units per Box. If product UoM is 'Kg': Box Quantity = "
'Ordered Quantity / Box Kilograms.'
)
elif self.config_type == 'units_as_boxes':
msg = _('If product UoM is \'Kg\': Box Quantity = Units per Box.')
msg = _("If product UoM is 'Kg': Box Quantity = Units per Box.")
self.config_type_description = msg
@api.constrains('customer_po_config_line_ids', 'partner')
def _validate_product(self):
CustomerPurchaseOrderConfigLine = self.env[
'customer.purchase.order.config.line'
]
CustomerPurchaseOrderConfigLine = self.env['customer.purchase.order.config.line']
config_lines = CustomerPurchaseOrderConfigLine.search(
[
@@ -108,9 +101,7 @@ class CustomerPurchaseOrderConfig(models.Model):
]
)
product_internal_code_dups = (
self._get_dups_for_product_and_internal_code(config_lines)
)
product_internal_code_dups = self._get_dups_for_product_and_internal_code(config_lines)
internal_code_dups = self._get_dups_for_internal_code(config_lines)
msg = ''
@@ -138,14 +129,9 @@ class CustomerPurchaseOrderConfig(models.Model):
ProductProduct = self.env['product.product']
dups = {}
product_code_ids = [
(line.product.id, line.product_internal_code)
for line in config_lines
]
product_code_dups = [
k for k, v in Counter(product_code_ids).items() if v > 1
]
product_code_ids = [(line.product.id, line.product_internal_code) for line in config_lines]
product_code_dups = [k for k, v in Counter(product_code_ids).items() if v > 1]
for dup in product_code_dups:
_product = dup[0]
internal_code = dup[1]
@@ -153,9 +139,9 @@ class CustomerPurchaseOrderConfig(models.Model):
product = ProductProduct.search([('id', '=', _product)])
product_name = '[%s] %s' % (product.default_code, product.name)
_config_name = config_lines.filtered(
lambda x: x.product_internal_code == internal_code
)[0].customer_purchase_order_config_id.name
_config_name = config_lines.filtered(lambda x: x.product_internal_code == internal_code)[
0
].customer_purchase_order_config_id.name
dups[int(product.default_code)] = _(
' ~ Product %s with Internal Code %s has already been set in Purchase '
@@ -176,9 +162,7 @@ class CustomerPurchaseOrderConfig(models.Model):
if line.product_internal_code not in codes.keys():
codes[line.product_internal_code] = []
codes[line.product_internal_code].append(
line.customer_purchase_order_config_id
)
codes[line.product_internal_code].append(line.customer_purchase_order_config_id)
dup_codes = {}
for k, v in codes.items():
@@ -187,8 +171,7 @@ class CustomerPurchaseOrderConfig(models.Model):
for k, v in dup_codes.items():
dups[k] = _(
' ~ Internal Code %s has already been set in Purchase Order '
'Configuration %s.\n'
' ~ Internal Code %s has already been set in Purchase Order ' 'Configuration %s.\n'
) % (
k,
', '.join([c for c in sorted([x.name for x in v])]),
@@ -220,15 +203,9 @@ class CustomerPurchaseOrderConfigLine(models.Model):
_description = 'Customer Purchase Order Configuration Line'
product = fields.Many2one('product.product', string='Product')
product_code = fields.Char(
related='product.default_code', string='Product Code'
)
product_ean13_code = fields.Char(
related='product.barcode', string='EAN13 Code', store=True
)
product_internal_code = fields.Char(
string='Purchase Order Product Code', required=True
)
product_code = fields.Char(related='product.default_code', string='Product Code')
product_ean13_code = fields.Char(related='product.barcode', string='EAN13 Code', store=True)
product_internal_code = fields.Char(string='Purchase Order Product Code', required=True)
customer_purchase_order_config_id = fields.Many2one(
comodel_name='customer.purchase.order.config',
string='Customer Purchase Order Configuration',