Rename Uom to Unit.

This commit is contained in:
Albert Cervera i Areny 2023-09-13 20:15:43 +02:00
parent 01f7c6a522
commit 1cfaf1ebbb
2 changed files with 24 additions and 24 deletions

View file

@ -43,7 +43,7 @@ class Production(metaclass=PoolMeta):
pool = Pool() pool = Pool()
Uom = pool.get('product.uom') Uom = pool.get('product.uom')
initial = remainder = Uom.compute_qty(self.uom, self.quantity, uom) initial = remainder = Uom.compute_qty(self.unit, self.quantity, uom)
if remainder <= quantity: if remainder <= quantity:
# Splitted to quantity greater than produciton's quantity # Splitted to quantity greater than produciton's quantity
return [self] return [self]
@ -54,7 +54,7 @@ class Production(metaclass=PoolMeta):
# Maybe someone want customize the key of the dictionary # Maybe someone want customize the key of the dictionary
input2qty.setdefault(input_.product.id, 0) input2qty.setdefault(input_.product.id, 0)
input2qty[input_.product.id] += Uom.compute_qty( input2qty[input_.product.id] += Uom.compute_qty(
input_.uom, input_.quantity * factor, input_.unit, input_.quantity * factor,
input_.product.default_uom, input_.product.default_uom,
round=False) round=False)
output2qty = {} # amount for each output in splitted productions output2qty = {} # amount for each output in splitted productions
@ -62,7 +62,7 @@ class Production(metaclass=PoolMeta):
# Maybe someone want customize the key of the dictionary # Maybe someone want customize the key of the dictionary
output2qty.setdefault(output.product.id, 0) output2qty.setdefault(output.product.id, 0)
output2qty[output.product.id] += Uom.compute_qty( output2qty[output.product.id] += Uom.compute_qty(
output.uom, output.quantity * factor, output.unit, output.quantity * factor,
output.product.default_uom, output.product.default_uom,
round=False) round=False)
@ -92,7 +92,7 @@ class Production(metaclass=PoolMeta):
self.write([self], { self.write([self], {
'number': '%s-%02d' % (number, 1), 'number': '%s-%02d' % (number, 1),
'quantity': uom.round(remainder), 'quantity': uom.round(remainder),
'uom': uom.id, 'unit': uom.id,
'state': state, 'state': state,
}) })
self.write(productions, {'state': state}) self.write(productions, {'state': state})
@ -103,7 +103,7 @@ class Production(metaclass=PoolMeta):
production, = self.copy([self], { production, = self.copy([self], {
'number': number, 'number': number,
'quantity': quantity, 'quantity': quantity,
'uom': uom.id, 'unit': uom.id,
'inputs': None, 'inputs': None,
'outputs': None, 'outputs': None,
}) })
@ -129,17 +129,17 @@ class Production(metaclass=PoolMeta):
for move in current_moves: for move in current_moves:
pending_qty = Uom.compute_qty( pending_qty = Uom.compute_qty(
move.product.default_uom, product2pending_qty[move.product.id], move.product.default_uom, product2pending_qty[move.product.id],
move.uom, move.unit,
round=False) round=False)
if pending_qty < move.uom.rounding: if pending_qty < move.unit.rounding:
# Leave this input to current production # Leave this input to current production
continue continue
if (move.quantity - pending_qty) < move.uom.rounding: if (move.quantity - pending_qty) < move.unit.rounding:
# move.quantity <= pending_qty # move.quantity <= pending_qty
# Move this input to new production # Move this input to new production
product2pending_qty[move.product.id] -= Uom.compute_qty( product2pending_qty[move.product.id] -= Uom.compute_qty(
move.uom, move.quantity, move.product.default_uom, move.unit, move.quantity, move.product.default_uom,
round=False) round=False)
to_write.extend( to_write.extend(
([move], {relation_field: new_production.id})) ([move], {relation_field: new_production.id}))
@ -149,7 +149,7 @@ class Production(metaclass=PoolMeta):
# split move moving pending_qty to new production and leaving # split move moving pending_qty to new production and leaving
# remaining to current one # remaining to current one
product2pending_qty[move.product.id] = 0 product2pending_qty[move.product.id] = 0
new_move_qty = move.uom.round(pending_qty) new_move_qty = move.unit.round(pending_qty)
new_move, = Move.copy([move], { new_move, = Move.copy([move], {
relation_field: new_production.id, relation_field: new_production.id,
'quantity': new_move_qty, 'quantity': new_move_qty,
@ -157,7 +157,7 @@ class Production(metaclass=PoolMeta):
}) })
new_moves.append(new_move) new_moves.append(new_move)
to_write.extend(([move], { to_write.extend(([move], {
'quantity': move.uom.round(move.quantity - new_move_qty), 'quantity': move.unit.round(move.quantity - new_move_qty),
})) }))
if move.state != 'draft': if move.state != 'draft':
to_draft.append(move) to_draft.append(move)
@ -207,9 +207,9 @@ class SplitProduction(Wizard):
if not production.product or not production.quantity: if not production.product or not production.quantity:
raise UserError(gettext('production_split.no_product_nor_quantity', raise UserError(gettext('production_split.no_product_nor_quantity',
production=production.rec_name)) production=production.rec_name))
if production.uom: if production.unit:
default['uom'] = production.uom.id default['uom'] = production.unit.id
default['uom_category'] = production.uom.category.id default['uom_category'] = production.unit.category.id
return default return default
def transition_split(self): def transition_split(self):

View file

@ -88,16 +88,16 @@ class ProductionSplitTestCase(CompanyTestMixin, ModuleTestCase):
'inputs': [('create', [{ 'inputs': [('create', [{
'product': component1.id, 'product': component1.id,
'quantity': 5.0, 'quantity': 5.0,
'uom': unit.id, 'unit': unit.id,
}, { }, {
'product': component2.id, 'product': component2.id,
'quantity': 2.0, 'quantity': 2.0,
'uom': unit.id, 'unit': unit.id,
}])], }])],
'outputs': [('create', [{ 'outputs': [('create', [{
'product': product.id, 'product': product.id,
'quantity': 1.0, 'quantity': 1.0,
'uom': unit.id, 'unit': unit.id,
}])], }])],
}]) }])
@ -105,7 +105,7 @@ class ProductionSplitTestCase(CompanyTestMixin, ModuleTestCase):
production, = Production.create([{ production, = Production.create([{
'product': product.id, 'product': product.id,
'bom': bom.id, 'bom': bom.id,
'uom': unit.id, 'unit': unit.id,
'quantity': quantity, 'quantity': quantity,
'warehouse': warehouse.id, 'warehouse': warehouse.id,
'location': production_loc.id, 'location': production_loc.id,
@ -176,7 +176,7 @@ class ProductionSplitTestCase(CompanyTestMixin, ModuleTestCase):
self.assertEqual(component1_move.quantity, 100) self.assertEqual(component1_move.quantity, 100)
component1_move2, = Move.copy([component1_move], { component1_move2, = Move.copy([component1_move], {
'quantity': 10, 'quantity': 10,
'uom': box5.id, 'unit': box5.id,
}) })
component1_move.quantity = 50 component1_move.quantity = 50
component1_move.save() component1_move.save()
@ -186,7 +186,7 @@ class ProductionSplitTestCase(CompanyTestMixin, ModuleTestCase):
productions = production.split(10, unit) productions = production.split(10, unit)
self.assertEqual(len(productions), 2) self.assertEqual(len(productions), 2)
self.assertEqual([m.quantity for m in productions], [10, 10]) self.assertEqual([m.quantity for m in productions], [10, 10])
self.assertEqual(sorted([sorted([(m.quantity, m.uom.symbol) self.assertEqual(sorted([sorted([(m.quantity, m.unit.symbol)
for m in p.inputs]) for p in productions]), for m in p.inputs]) for p in productions]),
[[(10, u'b5'), (20, u'u')], [(20, u'u'), (50, u'u')]]) [[(10, u'b5'), (20, u'u')], [(20, u'u'), (50, u'u')]])
self.assertEqual([[m.quantity for m in p.outputs] for p in self.assertEqual([[m.quantity for m in p.outputs] for p in
@ -197,7 +197,7 @@ class ProductionSplitTestCase(CompanyTestMixin, ModuleTestCase):
productions = production.split(5, unit) productions = production.split(5, unit)
self.assertEqual(len(productions), 4) self.assertEqual(len(productions), 4)
self.assertEqual([m.quantity for m in productions], [5, 5, 5, 5]) self.assertEqual([m.quantity for m in productions], [5, 5, 5, 5])
self.assertEqual(sorted([sorted([(m.quantity, m.uom.symbol) self.assertEqual(sorted([sorted([(m.quantity, m.unit.symbol)
for m in p.inputs]) for p in productions]), for m in p.inputs]) for p in productions]),
[[(5, u'b5'), (10, u'u')], [(5, u'b5'), (10, u'u')], [[(5, u'b5'), (10, u'u')], [(5, u'b5'), (10, u'u')],
[(10, u'u'), (25, u'u')], [(10, u'u'), (25, u'u')]]) [(10, u'u'), (25, u'u')], [(10, u'u'), (25, u'u')]])
@ -208,7 +208,7 @@ class ProductionSplitTestCase(CompanyTestMixin, ModuleTestCase):
# split in 3 NON equal productions: input moves splitted # split in 3 NON equal productions: input moves splitted
productions = production.split(5, unit, count=2) productions = production.split(5, unit, count=2)
self.assertEqual(len(productions), 3) self.assertEqual(len(productions), 3)
res = sorted([(p.quantity, sorted([(m.quantity, m.uom.symbol) res = sorted([(p.quantity, sorted([(m.quantity, m.unit.symbol)
for m in p.inputs])) for p in productions]) for m in p.inputs])) for p in productions])
try: try:
self.assertEqual(res, [ self.assertEqual(res, [
@ -231,7 +231,7 @@ class ProductionSplitTestCase(CompanyTestMixin, ModuleTestCase):
# split in 3 NON equal productions and different production UoM # split in 3 NON equal productions and different production UoM
productions = production.split(1, box5, count=2) productions = production.split(1, box5, count=2)
self.assertEqual(len(productions), 3) self.assertEqual(len(productions), 3)
res = sorted([(p.quantity, sorted([(m.quantity, m.uom.symbol) res = sorted([(p.quantity, sorted([(m.quantity, m.unit.symbol)
for m in p.inputs])) for p in productions]) for m in p.inputs])) for p in productions])
try: try:
self.assertEqual(res, [ self.assertEqual(res, [
@ -304,7 +304,7 @@ class ProductionSplitTestCase(CompanyTestMixin, ModuleTestCase):
'bom': None, 'bom': None,
'outputs': [('create', [{ 'outputs': [('create', [{
'product': component2.id, 'product': component2.id,
'uom': unit.id, 'unit': unit.id,
'quantity': 2, 'quantity': 2,
'from_location': production_loc.id, 'from_location': production_loc.id,
'to_location': storage.id, 'to_location': storage.id,