diff --git a/models/customer_purchase_order_config.py b/models/customer_purchase_order_config.py index 71de2f4364b4960d326af7ef7499c3e4fc2dbe93..1a355604d3fd1afb251d2842fd1f64389b7b0dfa 100644 --- a/models/customer_purchase_order_config.py +++ b/models/customer_purchase_order_config.py @@ -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', diff --git a/models/customer_purchase_order_importer.py b/models/customer_purchase_order_importer.py index d7381375e5d0489c9e7304c996ec23252391224c..b0db07a42bb37a45e4e6594bcb8d7f679f2e4f57 100644 --- a/models/customer_purchase_order_importer.py +++ b/models/customer_purchase_order_importer.py @@ -236,33 +236,25 @@ class CustomerPurchaseOrderImporter(models.Model): def get_config_basic_vals(self, vals): return vals - def get_config_boxes_based_on_box_kg_vals(self, vals): - ProductProduct = self.env['product.product'] - + def get_config_boxes_based_on_units_vals(self, vals): for line in vals['pre_order_line_ids']: ordered_qty = line[2]['ordered_qty']['original'] - box_kg = line[2]['box_kg'] - - if ordered_qty and box_kg and box_kg > 0: - line[2]['box_qty']['modified'] = int(ordered_qty / box_kg) - else: - product_id = line[2]['product_id'] - product = ProductProduct.browse(product_id) + units_per_box = line[2]['units_per_box']['original'] - if product: - line[2]['errors'].append( - _('~ Box Kilograms not set for product {}.\n').format(product.name) - ) + if ordered_qty and units_per_box and units_per_box > 0: + line[2]['box_qty']['modified'] = int(ordered_qty / units_per_box) return vals - def get_config_boxes_based_on_units_vals(self, vals): + def get_config_boxes_in_kg_vals(self, vals): for line in vals['pre_order_line_ids']: + box_kg = line[2]['box_kg'] ordered_qty = line[2]['ordered_qty']['original'] - units_per_box = line[2]['units_per_box']['original'] - if ordered_qty and units_per_box and units_per_box > 0: - line[2]['box_qty']['modified'] = int(ordered_qty / units_per_box) + if ordered_qty and box_kg and box_kg > 0: + box_qty = ordered_qty / box_kg + line[2]['box_qty']['modified'] = int(box_qty) if box_qty >= 1 else 0 + line[2]['ordered_qty']['modified'] = box_qty return vals @@ -285,6 +277,16 @@ class CustomerPurchaseOrderImporter(models.Model): return vals + def get_config_gross_price_by_units_vals(self, vals): + for line in vals['pre_order_line_ids']: + units_per_box = line[2]['units_per_box']['original'] + content = line[2]['content'] + + if units_per_box and content and content > 0: + line[2]['gross_price_unit']['modified'] /= content + + return vals + def get_config_internal_code(self, partner, product_type=False): _configs = self.get_config(partner) if not _configs: