Skip to content

Commit

Permalink
backend: skip packaging w/out qty
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Jun 10, 2020
1 parent 70bacd1 commit a12e06b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
9 changes: 8 additions & 1 deletion shopfloor/actions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,17 @@ def _product_parser(self):
"display_name",
"default_code",
"barcode",
("packaging_ids:packaging", self._packaging_parser),
("packaging_ids:packaging", self._product_packaging),
("uom_id:uom", self._simple_record_parser() + ["factor", "rounding"]),
]

def _product_packaging(self, rec, field):
return self._jsonify(
rec.packaging_ids.filtered(lambda x: x.qty),
self._packaging_parser,
multi=True,
)

def picking_batch(self, record, with_pickings=False, **kw):
parser = self._picking_batch_parser
if with_pickings:
Expand Down
1 change: 1 addition & 0 deletions shopfloor/services/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def packaging(self):
"id": {"required": True, "type": "integer"},
"name": {"type": "string", "nullable": False, "required": True},
"qty": {"type": "float", "required": True},
"is_unit": {"type": "boolean", "required": False},
}

def picking_batch(self, with_pickings=False):
Expand Down
41 changes: 37 additions & 4 deletions shopfloor/tests/test_actions_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,42 @@ def assert_schema(self, schema, data):
self.assertTrue(validator.validate(data), validator.errors)

def _expected_location(self, record, **kw):
return {
data = {
"id": record.id,
"name": record.name,
"barcode": record.barcode,
}
data.update(kw)
return data

def _expected_product(self, record, **kw):
return {
data = {
"id": record.id,
"name": record.name,
"display_name": record.display_name,
"default_code": record.default_code,
"barcode": record.barcode,
"packaging": [self._expected_packaging(x) for x in record.packaging_ids],
"packaging": [
self._expected_packaging(x) for x in record.packaging_ids if x.qty
],
"uom": {
"factor": record.uom_id.factor,
"id": record.uom_id.id,
"name": record.uom_id.name,
"rounding": record.uom_id.rounding,
},
}
data.update(kw)
return data

def _expected_packaging(self, record, **kw):
return {
data = {
"id": record.id,
"name": record.name,
"qty": record.qty,
}
data.update(kw)
return data


class ActionsDataCase(ActionsDataCaseBase):
Expand Down Expand Up @@ -140,6 +148,31 @@ def test_data_picking(self):
}
self.assertDictEqual(data, expected)

def test_data_product(self):
(
self.env["product.packaging"]
.sudo()
.create(
{
"name": "Box 2",
"product_id": self.product_a.id,
"barcode": "ProductABox2",
}
)
)
self.product_a.packaging_ids.write({"qty": 0})
data = self.data.product(self.product_a)
self.assert_schema(self.schema.product(), data)
# No packaging expected as all qties are zero
expected = self._expected_product(self.product_a)
self.assertDictEqual(data, expected)
# packaging w/ no zero qty are included
self.product_a.packaging_ids[0].write({"qty": 100})
self.product_a.packaging_ids[1].write({"qty": 20})
data = self.data.product(self.product_a)
expected = self._expected_product(self.product_a)
self.assertDictEqual(data, expected)

def test_data_move_line_package(self):
move_line = self.move_a.move_line_ids
result_package = self.env["stock.quant.package"].create(
Expand Down

0 comments on commit a12e06b

Please sign in to comment.