Set location when get lot quantity in insemination event + float dose field according to number field decimals

#036622
#037047
This commit is contained in:
Raimon Esteve 2019-03-06 14:26:09 +01:00
parent 389d9d856d
commit 226fdbf5ec
3 changed files with 9 additions and 4 deletions

View File

@ -1189,7 +1189,7 @@ class EventUnion(UnionMixin, ModelSQL, ModelView):
def get_cycle(self, name=None):
model = self._get_event()
if hasattr(model, 'female_cycle'):
if hasattr(model, 'female_cycle') and model.female_cycle:
return model.female_cycle.id
return None

View File

@ -183,14 +183,18 @@ class InseminationEvent(AbstractEvent, ImportedEventMixin):
Move.do(todo_moves)
def _check_dose_in_farm(self):
Lot = Pool().get('stock.lot')
if self.dose_lot:
with Transaction().set_context(
locations=[self.farm.storage_location.id],
stock_date_end=self.timestamp.date()):
return self.dose_lot.quantity > 0
return Lot.get_quantity([self.dose_lot], 'quantity')[self.dose_lot.id] > 0
# return self.dose_lot.quantity > 0
product = self.dose_product or self.specie.semen_product
if product.consumable:
return True
with Transaction().set_context(
stock_date_end=self.timestamp.date(),
locations=[self.farm.storage_location.id]):

View File

@ -2,7 +2,7 @@
#copyright notices and license terms.
import math
from datetime import datetime, date
from decimal import Decimal
from trytond.model import fields, ModelView, ModelSQL, Workflow
from trytond.pyson import Bool, Equal, Eval, Greater, Id
from trytond.pool import Pool
@ -240,7 +240,8 @@ class SemenExtractionEvent(AbstractEvent):
assert consumed_semen_qty > 0.0, ('BOM of semen extraction event "%s" '
'generetes 0.0 consumed semen qty' % self.id)
n_doses = float(self.semen_qty) / consumed_semen_qty
return n_doses
digits = self.__class__.dose_calculated_units.digits[1]
return float(Decimal(n_doses).quantize(Decimal(str(10.0 ** -digits))))
@fields.depends('semen_qty', 'doses')
def on_change_with_doses_semen_qty(self, name=None):