summaryrefslogtreecommitdiff
path: root/addons/delivery/models/product_packaging.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/delivery/models/product_packaging.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/delivery/models/product_packaging.py')
-rw-r--r--addons/delivery/models/product_packaging.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/addons/delivery/models/product_packaging.py b/addons/delivery/models/product_packaging.py
new file mode 100644
index 00000000..939a6dd0
--- /dev/null
+++ b/addons/delivery/models/product_packaging.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models, fields, api
+
+
+class ProductPackaging(models.Model):
+ _inherit = 'product.packaging'
+
+
+ def _get_default_length_uom(self):
+ return self.env['product.template']._get_length_uom_name_from_ir_config_parameter()
+
+ def _get_default_weight_uom(self):
+ return self.env['product.template']._get_weight_uom_name_from_ir_config_parameter()
+
+ height = fields.Integer('Height')
+ width = fields.Integer('Width')
+ packaging_length = fields.Integer('Length')
+ max_weight = fields.Float('Max Weight', help='Maximum weight shippable in this packaging')
+ shipper_package_code = fields.Char('Package Code')
+ package_carrier_type = fields.Selection([('none', 'No carrier integration')], string='Carrier', default='none')
+ weight_uom_name = fields.Char(string='Weight unit of measure label', compute='_compute_weight_uom_name', default=_get_default_weight_uom)
+ length_uom_name = fields.Char(string='Length unit of measure label', compute='_compute_length_uom_name', default=_get_default_length_uom)
+
+ _sql_constraints = [
+ ('positive_height', 'CHECK(height>=0)', 'Height must be positive'),
+ ('positive_width', 'CHECK(width>=0)', 'Width must be positive'),
+ ('positive_length', 'CHECK(packaging_length>=0)', 'Length must be positive'),
+ ('positive_max_weight', 'CHECK(max_weight>=0.0)', 'Max Weight must be positive'),
+ ]
+
+ @api.onchange('package_carrier_type')
+ def _onchange_carrier_type(self):
+ carrier_id = self.env['delivery.carrier'].search([('delivery_type', '=', self.package_carrier_type)], limit=1)
+ if carrier_id:
+ self.shipper_package_code = carrier_id._get_default_custom_package_code()
+ else:
+ self.shipper_package_code = False
+
+
+ def _compute_length_uom_name(self):
+ for packaging in self:
+ packaging.length_uom_name = self.env['product.template']._get_length_uom_name_from_ir_config_parameter()
+
+ def _compute_weight_uom_name(self):
+ for packaging in self:
+ packaging.weight_uom_name = self.env['product.template']._get_weight_uom_name_from_ir_config_parameter()