parent
e53d05e0e9
commit
bfcc5b0142
|
@ -42,7 +42,6 @@ def register():
|
|||
stock.LocationSiloLocation,
|
||||
stock.LotAnimalGroup,
|
||||
stock.Lot,
|
||||
stock.LotCostLine,
|
||||
user.User,
|
||||
user.UserLocation,
|
||||
product.Template,
|
||||
|
|
|
@ -487,10 +487,6 @@ class Animal(ModelSQL, ModelView, AnimalMixin):
|
|||
'animal_type': animal_vals['type'],
|
||||
'animal': animal_vals['id']
|
||||
}
|
||||
if Transaction().context.get('create_cost_lines', True):
|
||||
cost_lines = lot_tmp._on_change_product_cost_lines().get('add')
|
||||
if cost_lines:
|
||||
res['cost_lines'] = [('create', [cl[1] for cl in cost_lines])]
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -449,18 +449,10 @@ class AnimalGroup(ModelSQL, ModelView, AnimalMixin):
|
|||
assert specie.group_product
|
||||
|
||||
group_product = specie.group_product.id
|
||||
lot_tmp = Lot(product=group_product)
|
||||
cost_lines = None
|
||||
if lot_tmp:
|
||||
lot_tmp_vals = lot_tmp._on_change_product_cost_lines()
|
||||
if lot_tmp_vals:
|
||||
cost_lines = lot_tmp_vals.get('add')
|
||||
return {
|
||||
'number': group_vals['number'],
|
||||
'product': group_product,
|
||||
'animal_type': 'group',
|
||||
'cost_lines': ([('create', [cl[1] for cl in cost_lines])]
|
||||
if cost_lines else []),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -177,9 +177,7 @@ class FarrowingEvent(AbstractEvent, ImportedEventMixin, ModelSQL, ModelView, Wor
|
|||
farrowing_event.female_cycle = current_cycle
|
||||
|
||||
if farrowing_event.live != 0:
|
||||
with Transaction().set_context(
|
||||
no_create_stock_move=True,
|
||||
create_cost_lines=False):
|
||||
with Transaction().set_context(no_create_stock_move=True):
|
||||
if farrowing_event.produced_animal_type == 'individual':
|
||||
for i in range(farrowing_event.live):
|
||||
produced_animal = farrowing_event._get_produced_animal()
|
||||
|
@ -234,13 +232,8 @@ class FarrowingEvent(AbstractEvent, ImportedEventMixin, ModelSQL, ModelView, Wor
|
|||
def _get_event_move(self, animal=None):
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
ModelData = pool.get('ir.model.data')
|
||||
LotCostLine = pool.get('stock.lot.cost_line')
|
||||
Company = pool.get('company.company')
|
||||
|
||||
category_id = ModelData.get_id('farm', 'cost_category_farrowing_cost')
|
||||
|
||||
context = Transaction().context
|
||||
Company = pool.get('company.company')
|
||||
company = Company(context['company'])
|
||||
|
||||
if self.produced_animal_type == 'individual':
|
||||
|
@ -254,17 +247,6 @@ class FarrowingEvent(AbstractEvent, ImportedEventMixin, ModelSQL, ModelView, Wor
|
|||
uom = self.specie.group_product.default_uom.id
|
||||
live = self.live
|
||||
|
||||
if lot and lot.product.template.farrowing_price:
|
||||
if lot.cost_lines:
|
||||
cost_line = lot.cost_lines[0]
|
||||
else:
|
||||
cost_line = LotCostLine()
|
||||
cost_line.lot = lot
|
||||
cost_line.category = category_id
|
||||
cost_line.origin = str(self)
|
||||
cost_line.unit_price = lot.product.template.farrowing_price
|
||||
cost_line.save()
|
||||
|
||||
return Move(
|
||||
product=product,
|
||||
uom=uom,
|
||||
|
|
|
@ -237,28 +237,13 @@ class MoveEvent(AbstractEvent):
|
|||
def _get_event_move(self):
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
ModelData = pool.get('ir.model.data')
|
||||
LotCostLine = pool.get('stock.lot.cost_line')
|
||||
Company = pool.get('company.company')
|
||||
|
||||
category_id = ModelData.get_id('stock_lot_cost',
|
||||
'cost_category_standard_price')
|
||||
|
||||
context = Transaction().context
|
||||
company = Company(context['company'])
|
||||
|
||||
lot = (self.animal_type != 'group' and self.animal.lot or
|
||||
self.animal_group.lot)
|
||||
|
||||
if lot and self.unit_price and lot.cost_price != self.unit_price:
|
||||
cost_line = LotCostLine()
|
||||
cost_line.lot = lot
|
||||
cost_line.category = category_id
|
||||
cost_line.origin = str(self)
|
||||
cost_line.unit_price = (self.unit_price - lot.cost_price
|
||||
if lot.cost_price else self.unit_price)
|
||||
cost_line.save()
|
||||
|
||||
return Move(
|
||||
product=lot.product,
|
||||
uom=lot.product.default_uom,
|
||||
|
|
|
@ -148,10 +148,6 @@ class ReclassficationEvent(AbstractEvent):
|
|||
'animal_type': self.animal.type,
|
||||
'animal': self.animal,
|
||||
}
|
||||
if Transaction().context.get('create_cost_lines', True):
|
||||
cost_lines = lot_tmp._on_change_product_cost_lines().get('add')
|
||||
if cost_lines:
|
||||
res['cost_lines'] = [('create', [cl[1] for cl in cost_lines])]
|
||||
return res
|
||||
|
||||
def _get_event_input_move(self):
|
||||
|
|
|
@ -360,17 +360,6 @@ class WeaningEvent(AbstractEvent, ImportedEventMixin):
|
|||
|
||||
weaning_event.weaned_move = weaned_move
|
||||
todo_moves.append(weaned_move)
|
||||
if weaning_event.produced_animal_type == 'individual':
|
||||
for animal in weaning_event.weaned_animals:
|
||||
cost_line = (
|
||||
weaning_event._get_weaning_animal_cost_line(
|
||||
animal.animal))
|
||||
if cost_line:
|
||||
cost_line.save()
|
||||
else:
|
||||
cost_line = weaning_event._get_weaning_cost_line()
|
||||
if cost_line:
|
||||
cost_line.save()
|
||||
|
||||
weaning_event.save()
|
||||
current_cycle.update_state(weaning_event)
|
||||
|
@ -378,8 +367,7 @@ class WeaningEvent(AbstractEvent, ImportedEventMixin):
|
|||
Move.assign(todo_moves)
|
||||
Move.do(todo_moves)
|
||||
if todo_trans_events:
|
||||
with Transaction().set_context(create_cost_lines=False):
|
||||
TransformationEvent.validate_event(todo_trans_events)
|
||||
TransformationEvent.validate_event(todo_trans_events)
|
||||
|
||||
def _get_female_move(self):
|
||||
pool = Pool()
|
||||
|
@ -462,43 +450,6 @@ class WeaningEvent(AbstractEvent, ImportedEventMixin):
|
|||
lot=self.farrowing_group.lot,
|
||||
origin=self)
|
||||
|
||||
def _get_weaning_animal_cost_line(self, animal):
|
||||
pool = Pool()
|
||||
ModelData = pool.get('ir.model.data')
|
||||
LotCostLine = pool.get('stock.lot.cost_line')
|
||||
category_id = ModelData.get_id('farm', 'cost_category_weaning_cost')
|
||||
|
||||
if (animal.lot and animal.lot.product.template.weaning_price and
|
||||
animal.lot.product.template.weaning_price !=
|
||||
animal.lot.cost_price):
|
||||
cost_line = LotCostLine()
|
||||
cost_line.lot = animal.lot
|
||||
cost_line.category = category_id
|
||||
cost_line.origin = str(self)
|
||||
cost_line.unit_price = (animal.lot.product.template.weaning_price -
|
||||
animal.lot.cost_price)
|
||||
return cost_line
|
||||
|
||||
def _get_weaning_cost_line(self):
|
||||
pool = Pool()
|
||||
ModelData = pool.get('ir.model.data')
|
||||
LotCostLine = pool.get('stock.lot.cost_line')
|
||||
category_id = ModelData.get_id('farm', 'cost_category_weaning_cost')
|
||||
group = (self.weaned_group if self.weaned_group
|
||||
else self.farrowing_group)
|
||||
if not group:
|
||||
raise UserError(gettext('farm.not_farrowing_group', event=self))
|
||||
if (group.lot and group.lot.product.template.weaning_price and
|
||||
group.lot.product.template.weaning_price !=
|
||||
group.lot.cost_price):
|
||||
cost_line = LotCostLine()
|
||||
cost_line.lot = group.lot
|
||||
cost_line.category = category_id
|
||||
cost_line.origin = str(self)
|
||||
cost_line.unit_price = (group.lot.product.template.weaning_price -
|
||||
group.lot.cost_price)
|
||||
return cost_line
|
||||
|
||||
def _get_weaned_move(self, animal=None):
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
|
|
|
@ -4483,14 +4483,6 @@ msgctxt "model:stock.lot-farm.animal.group,name:"
|
|||
msgid "Lot - Animal Group"
|
||||
msgstr "Lot - Animal Group"
|
||||
|
||||
msgctxt "model:stock.lot.cost_category,name:cost_category_farrowing_cost"
|
||||
msgid "Farrowing Cost"
|
||||
msgstr "Cost del part"
|
||||
|
||||
msgctxt "model:stock.lot.cost_category,name:cost_category_weaning_cost"
|
||||
msgid "Weaning Cost"
|
||||
msgstr "Weaning Cost"
|
||||
|
||||
msgctxt "selection:farm.abort.event,animal_type:"
|
||||
msgid "Female"
|
||||
msgstr "Femella"
|
||||
|
|
|
@ -4084,14 +4084,6 @@ msgctxt "model:stock.lot-farm.animal.group,name:"
|
|||
msgid "Lot - Animal Group"
|
||||
msgstr "Lote - Grupo de animales"
|
||||
|
||||
msgctxt "model:stock.lot.cost_category,name:cost_category_farrowing_cost"
|
||||
msgid "Farrowing Cost"
|
||||
msgstr "Coste de parto"
|
||||
|
||||
msgctxt "model:stock.lot.cost_category,name:cost_category_weaning_cost"
|
||||
msgid "Weaning Cost"
|
||||
msgstr "Coste destete"
|
||||
|
||||
msgctxt "selection:farm.abort.event,animal_type:"
|
||||
msgid "Female"
|
||||
msgstr "Hembra"
|
||||
|
|
16
stock.py
16
stock.py
|
@ -402,19 +402,3 @@ class Move(metaclass=PoolMeta):
|
|||
move.lot.animal.location = move.to_location.id
|
||||
move.lot.animal.save()
|
||||
return res
|
||||
|
||||
|
||||
class LotCostLine(metaclass=PoolMeta):
|
||||
__name__ = 'stock.lot.cost_line'
|
||||
|
||||
@classmethod
|
||||
def _get_origin(cls):
|
||||
models = super(LotCostLine, cls)._get_origin()
|
||||
models += [
|
||||
'farm.move.event',
|
||||
'farm.transformation.event',
|
||||
'farm.farrowing.event',
|
||||
'farm.weaning.event',
|
||||
'farm.reclassification.event'
|
||||
]
|
||||
return models
|
||||
|
|
10
stock.xml
10
stock.xml
|
@ -80,14 +80,4 @@
|
|||
<field name="perm_delete" eval="True"/>
|
||||
</record>
|
||||
</data>
|
||||
<data noupdate="1">
|
||||
<record model="stock.lot.cost_category"
|
||||
id="cost_category_farrowing_cost">
|
||||
<field name="name">Farrowing Cost</field>
|
||||
</record>
|
||||
<record model="stock.lot.cost_category"
|
||||
id="cost_category_weaning_cost">
|
||||
<field name="name">Weaning Cost</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -263,7 +263,5 @@ it is 'mated' and check female functional fields values::
|
|||
Female childs must have the farrowing cost::
|
||||
|
||||
>>> group = farrow_event2.produced_group
|
||||
>>> len(group.lot.cost_lines)
|
||||
1
|
||||
>>> group.lot.cost_price == Decimal('20.0')
|
||||
True
|
||||
|
|
|
@ -119,7 +119,7 @@ Validate individual move event::
|
|||
Create individual move event changing cost price::
|
||||
|
||||
>>> individual.lot.cost_price
|
||||
Decimal('25')
|
||||
Decimal('25.0000')
|
||||
>>> config.user = individual_user.id
|
||||
>>> move_individual = MoveEvent()
|
||||
>>> move_individual.animal_type = 'individual'
|
||||
|
@ -140,11 +140,7 @@ Create individual move event changing cost price::
|
|||
>>> individual.location == location1
|
||||
True
|
||||
>>> individual.lot.cost_price
|
||||
Decimal('30.0')
|
||||
>>> move_cost_line, = [x for x in individual.lot.cost_lines
|
||||
... if x.origin == move_individual]
|
||||
>>> move_cost_line.unit_price
|
||||
Decimal('5.0')
|
||||
Decimal('25.0000')
|
||||
|
||||
Create group::
|
||||
|
||||
|
|
|
@ -100,8 +100,6 @@ Validate transformation event::
|
|||
1
|
||||
>>> to_animal.type
|
||||
'individual'
|
||||
>>> len(to_animal.lot.cost_lines) == 1
|
||||
True
|
||||
>>> to_animal.lot.cost_price == individual_product.cost_price
|
||||
True
|
||||
>>> to_animal.location == transform_male_to_individual.to_location
|
||||
|
|
|
@ -238,13 +238,7 @@ the weaning event doesn't have female, weaned nor lost moves::
|
|||
>>> female1.current_cycle.weaning_event.weaned_move
|
||||
>>> female1.current_cycle.weaning_event.lost_move
|
||||
>>> lot = weaning_event1.farrowing_group.lot
|
||||
>>> len(lot.cost_lines)
|
||||
2
|
||||
>>> lot.cost_price == Decimal('25.0')
|
||||
True
|
||||
>>> weaning_cost_line, = [x for x in lot.cost_lines
|
||||
... if x.origin == weaning_event1]
|
||||
>>> weaning_cost_line.unit_price == Decimal('5')
|
||||
>>> lot.cost_price == Decimal('20.0000')
|
||||
True
|
||||
|
||||
Create a weaning event for second female (7 lives) with 6 as quantity, with
|
||||
|
@ -375,12 +369,5 @@ weaned group moves::
|
|||
>>> female4.current_cycle.weaning_event.transformation_event.state
|
||||
'validated'
|
||||
>>> lot = weaning_event4.weaned_group.lot
|
||||
>>> len(lot.cost_lines)
|
||||
2
|
||||
>>> lot.cost_price == Decimal('25.0')
|
||||
>>> lot.cost_price == Decimal('20.0000')
|
||||
True
|
||||
>>> weaning_cost_line, = [x for x in lot.cost_lines
|
||||
... if x.origin == weaning_event4]
|
||||
>>> weaning_cost_line.unit_price == Decimal('5.0')
|
||||
True
|
||||
|
||||
|
|
Loading…
Reference in New Issue