Add another product to distinct for which animal is the nutrition program defined
This commit is contained in:
parent
7b5b18a7c2
commit
028e7b0b8a
|
@ -17,6 +17,7 @@ class NutritionProgram(ModelSQL, ModelView):
|
|||
start_weight = fields.Float('Start Weight')
|
||||
end_weight = fields.Float('End Weight')
|
||||
product = fields.Many2One('product.product', 'Product', required=True)
|
||||
animal_product = fields.Many2One('product.product', 'Animal Product')
|
||||
bom = fields.Function(fields.Many2One('production.bom', 'BOM',
|
||||
domain=[
|
||||
('output_products', '=', Eval('product', 0)),
|
||||
|
@ -48,16 +49,19 @@ class StockLot:
|
|||
if not animal:
|
||||
return
|
||||
|
||||
domain = [('product', '=', self.product)]
|
||||
domain = [('animal_product', '=', self.product)]
|
||||
order = [('end_weight', 'DESC')]
|
||||
weight_domain = []
|
||||
if animal.current_weight:
|
||||
weight = animal.current_weight.weight
|
||||
domain.extend([
|
||||
weight_domain = [
|
||||
('start_weight', '<=', weight),
|
||||
('end_weight', '>=', weight),
|
||||
], )
|
||||
programs = Program.search(domain, order=[
|
||||
('end_weight', 'DESC'),
|
||||
], limit=1)
|
||||
]
|
||||
programs = Program.search(domain + weight_domain, order=order, limit=1)
|
||||
if len(programs) > 0:
|
||||
return programs[0].id
|
||||
programs = Program.search(weight_domain, order=order, limit=1)
|
||||
if len(programs) > 0:
|
||||
return programs[0].id
|
||||
|
||||
|
|
|
@ -85,6 +85,15 @@ Create products::
|
|||
>>> group_template.save()
|
||||
>>> group_product = Product(template=group_template)
|
||||
>>> group_product.save()
|
||||
>>> grain_template = ProductTemplate(
|
||||
... name='Graing',
|
||||
... default_uom=unit,
|
||||
... type='goods',
|
||||
... list_price=Decimal('40'),
|
||||
... cost_price=Decimal('25'))
|
||||
>>> grain_template.save()
|
||||
>>> grain_product = Product(template=grain_template)
|
||||
>>> grain_product.save()
|
||||
|
||||
Create sequence::
|
||||
|
||||
|
@ -177,7 +186,8 @@ Create nutrition program::
|
|||
>>> nutrition_program = NutritionProgram(
|
||||
... start_weight=10.0,
|
||||
... end_weight=30.0,
|
||||
... product=individual_product)
|
||||
... product=grain_product)
|
||||
... animal_product=individual_product)
|
||||
>>> nutrition_program.save()
|
||||
>>> individual.lot.nutrition_program == None
|
||||
True
|
||||
|
@ -202,7 +212,8 @@ Create another nutrition program::
|
|||
>>> nutrition_program2 = NutritionProgram(
|
||||
... start_weight=50.0,
|
||||
... end_weight=70.0,
|
||||
... product=individual_product)
|
||||
... product=grain_product)
|
||||
... animal_product=individual_product)
|
||||
>>> nutrition_program2.save()
|
||||
>>> AnimalWeight = Model.get('farm.animal.weight')
|
||||
>>> kg, = ProductUom.find([('name', '=', 'Kilogram')])
|
||||
|
|
|
@ -10,4 +10,6 @@
|
|||
<field name="product"/>
|
||||
<label name="bom"/>
|
||||
<field name="bom"/>
|
||||
<label name="animal_product"/>
|
||||
<field name="animal_product"/>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue