mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[FIX] issues with stock_cubiscan
* was using a link to product.template in the wizard instead of product.product * use product.packaging.type instead of the name of the packaging * update product_packaging_type from OCA * fix the numbe of digits of the volume
This commit is contained in:
committed by
Guewen Baconnier
parent
76eccd3a40
commit
a485d344c7
@@ -10,7 +10,8 @@
|
||||
'depends': [
|
||||
'barcodes',
|
||||
'stock',
|
||||
'web_tree_dynamic_colored_field'
|
||||
'web_tree_dynamic_colored_field',
|
||||
'product_packaging_type_required',
|
||||
],
|
||||
'website': 'http://www.camptocamp.com',
|
||||
'data': [
|
||||
|
||||
@@ -14,6 +14,14 @@ class StockWarehouse(models.Model):
|
||||
|
||||
class ProductPackaging(models.Model):
|
||||
_inherit = "product.packaging"
|
||||
_sql_constraints = [
|
||||
(
|
||||
'product_packaging_type_unique',
|
||||
'unique (product_id, packaging_type_id)',
|
||||
'It is forbidden to have different packagings '
|
||||
'with the same type for a given product.',
|
||||
)
|
||||
]
|
||||
|
||||
# TODO move these in an addon. Warning:
|
||||
# * 'delivery' defines the same fields and add them in the 'Delivery
|
||||
@@ -21,11 +29,16 @@ class ProductPackaging(models.Model):
|
||||
# * our put-away modules (wms/stock_putaway_storage_type_strategy) will
|
||||
# need these fields as well
|
||||
max_weight = fields.Float()
|
||||
length = fields.Integer()
|
||||
width = fields.Integer()
|
||||
height = fields.Integer()
|
||||
length = fields.Integer('Length (mm)', help='length in millimeters')
|
||||
width = fields.Integer('Width (mm)', help='width in millimeters')
|
||||
height = fields.Integer('Height (mm)', help='height in millimeters')
|
||||
volume = fields.Float(
|
||||
compute='_compute_volume', readonly=True, store=False
|
||||
'Volume (m³)',
|
||||
digits=(8, 4),
|
||||
compute='_compute_volume',
|
||||
readonly=True,
|
||||
store=False,
|
||||
help='volume in cubic meters',
|
||||
)
|
||||
|
||||
@api.depends('length', 'width', 'height')
|
||||
|
||||
@@ -29,6 +29,24 @@ class TestCubiscanWizard(SavepointCase):
|
||||
|
||||
cls.device_obj = cls.env['cubiscan.device']
|
||||
cls.cs_wizard = cls.env['cubiscan.wizard']
|
||||
PackType = cls.env['product.packaging.type']
|
||||
pack_type_data = [
|
||||
('unit', 1, 0, 0),
|
||||
('internal', 2, 1, 0),
|
||||
('retail', 10, 1, 1),
|
||||
('transport', 20, 1, 1),
|
||||
('pallet', 30, 1, 1),
|
||||
]
|
||||
for name, seq, gtin, req in pack_type_data:
|
||||
PackType.create(
|
||||
{
|
||||
'name': name,
|
||||
'code': name.upper(),
|
||||
'sequence': seq,
|
||||
'has_gtin': gtin,
|
||||
'required': req,
|
||||
}
|
||||
)
|
||||
|
||||
cls.device = cls.device_obj.create(
|
||||
{
|
||||
@@ -41,14 +59,11 @@ class TestCubiscanWizard(SavepointCase):
|
||||
|
||||
cls.wizard = cls.cs_wizard.create({'device_id': cls.device.id})
|
||||
|
||||
cls.product_1 = cls.env.ref(
|
||||
'product.product_product_6'
|
||||
).product_tmpl_id
|
||||
cls.product_2 = cls.env.ref(
|
||||
'product.product_product_7'
|
||||
).product_tmpl_id
|
||||
cls.product_1 = cls.env.ref('product.product_product_6')
|
||||
cls.product_2 = cls.env.ref('product.product_product_7')
|
||||
|
||||
cls.product_1.barcode = '424242'
|
||||
PackType.cron_check_create_required_packaging()
|
||||
|
||||
def test_product_onchange(self):
|
||||
self.wizard.product_id = self.product_1.id
|
||||
|
||||
@@ -10,24 +10,36 @@ class CubiscanWizard(models.TransientModel):
|
||||
_description = 'Cubiscan Wizard'
|
||||
_rec_name = 'device_id'
|
||||
|
||||
PACKAGING_UNITS = ['Unit', 'kfVE', 'DhVE', 'KrVE', 'PAL']
|
||||
|
||||
device_id = fields.Many2one('cubiscan.device', readonly=True)
|
||||
product_id = fields.Many2one('product.template')
|
||||
product_id = fields.Many2one(
|
||||
'product.product', domain=[('type', '=', 'product')]
|
||||
)
|
||||
line_ids = fields.One2many('cubiscan.wizard.line', 'wizard_id')
|
||||
|
||||
@api.onchange('product_id')
|
||||
def onchange_product_id(self):
|
||||
if self.product_id:
|
||||
to_create = []
|
||||
for seq, name in enumerate(self.PACKAGING_UNITS):
|
||||
pack = self.product_id.packaging_ids.filtered(
|
||||
lambda rec: rec.name == name
|
||||
packaging_types = self.env['product.packaging.type'].search([])
|
||||
for seq, pack_type in enumerate(packaging_types):
|
||||
pack = self.env['product.packaging'].search(
|
||||
[
|
||||
('product_id', '=', self.product_id.id),
|
||||
('packaging_type_id', '=', pack_type.id),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
vals = {
|
||||
'wizard_id': self.id,
|
||||
'sequence': seq + 1,
|
||||
'name': name,
|
||||
'name': pack_type.name,
|
||||
'qty': 0,
|
||||
'max_weight': 0,
|
||||
'length': 0,
|
||||
'width': 0,
|
||||
'height': 0,
|
||||
'barcode': False,
|
||||
'packaging_type_id': pack_type.id,
|
||||
}
|
||||
if pack:
|
||||
vals.update(
|
||||
@@ -38,11 +50,13 @@ class CubiscanWizard(models.TransientModel):
|
||||
'width': pack.width,
|
||||
'height': pack.height,
|
||||
'barcode': pack.barcode,
|
||||
'packaging_id': pack.id,
|
||||
'packaging_type_id': pack_type.id,
|
||||
}
|
||||
)
|
||||
to_create.append(vals)
|
||||
recs = self.env['cubiscan.wizard.line'].create(to_create)
|
||||
self.line_ids = [(6, 0, recs.ids)]
|
||||
self.line_ids = recs
|
||||
else:
|
||||
self.line_ids = [(5, 0, 0)]
|
||||
|
||||
@@ -66,7 +80,7 @@ class CubiscanWizard(models.TransientModel):
|
||||
@api.multi
|
||||
def on_barcode_scanned(self, barcode):
|
||||
self.ensure_one()
|
||||
prod = self.env['product.template'].search([('barcode', '=', barcode)])
|
||||
prod = self.env['product.product'].search([('barcode', '=', barcode)])
|
||||
self.product_id = prod
|
||||
self.onchange_product_id()
|
||||
|
||||
@@ -76,7 +90,6 @@ class CubiscanWizard(models.TransientModel):
|
||||
actions = []
|
||||
for line in self.line_ids:
|
||||
vals = {
|
||||
'sequence': line.sequence,
|
||||
'name': line.name,
|
||||
'qty': line.qty,
|
||||
'max_weight': line.max_weight,
|
||||
@@ -84,10 +97,9 @@ class CubiscanWizard(models.TransientModel):
|
||||
'width': line.width,
|
||||
'height': line.height,
|
||||
'barcode': line.barcode,
|
||||
'packaging_type_id': line.packaging_type_id.id,
|
||||
}
|
||||
pack = self.product_id.packaging_ids.filtered(
|
||||
lambda rec: rec.name == line.name
|
||||
)
|
||||
pack = line.packaging_id
|
||||
if pack:
|
||||
actions.append((1, pack.id, vals))
|
||||
else:
|
||||
@@ -132,9 +144,20 @@ class CubiscanWizardLine(models.TransientModel):
|
||||
width = fields.Integer("Width (mm)", readonly=True)
|
||||
height = fields.Integer("Height (mm)", readonly=True)
|
||||
volume = fields.Float(
|
||||
"Volume (m3)", compute='_compute_volume', readonly=True, store=False
|
||||
"Volume (m³)",
|
||||
digits=(8, 4),
|
||||
compute='_compute_volume',
|
||||
readonly=True,
|
||||
store=False,
|
||||
)
|
||||
barcode = fields.Char("GTIN")
|
||||
packaging_id = fields.Many2one('product.packaging', readonly=True)
|
||||
packaging_type_id = fields.Many2one(
|
||||
'product.packaging.type', readonly=True, required=True
|
||||
)
|
||||
required = fields.Boolean(
|
||||
related='packaging_type_id.required', readonly=True
|
||||
)
|
||||
|
||||
@api.depends('length', 'width', 'height')
|
||||
def _compute_volume(self):
|
||||
|
||||
@@ -19,13 +19,14 @@
|
||||
<field name="line_ids">
|
||||
<tree editable="bottom" create="0" delete="0">
|
||||
<field name="sequence" invisible="1" />
|
||||
<field name="required" invisible="1" />
|
||||
<field name="name" />
|
||||
<field name="qty" />
|
||||
<field name="max_weight" options="{'bg_color': 'lightcoral: max_weight == 0.0'}" />
|
||||
<field name="length" options="{'bg_color': 'lightcoral: length == 0.0'}" />
|
||||
<field name="width" options="{'bg_color': 'lightcoral: width == 0.0'}" />
|
||||
<field name="height" options="{'bg_color': 'lightcoral: height == 0.0'}" />
|
||||
<field name="volume" options="{'bg_color': 'lightcoral: volume == 0.0'}" />
|
||||
<field name="max_weight" options="{'bg_color': 'lightcoral: max_weight == 0.0 and required'}" />
|
||||
<field name="length" options="{'bg_color': 'lightcoral: length == 0.0 and required'}" />
|
||||
<field name="width" options="{'bg_color': 'lightcoral: width == 0.0 and required'}" />
|
||||
<field name="height" options="{'bg_color': 'lightcoral: height == 0.0 and required'}" />
|
||||
<field name="volume" options="{'bg_color': 'lightcoral: volume == 0.0 and required'}" />
|
||||
<button name="cubiscan_measure" type="object" string="CubiScan" class="btn btn-warning" />
|
||||
<field name="barcode" />
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user