Fix Many2Many auxiliar models and fixes after python-sql patch
* Add 'ondelete' attribute to most of the fields of Many2Many auxiliar models * Replace False by None in domains and filter clauses over Many2One fields * Return the ID in last_produced_group getter * Explicit conversion to tuple the domain recived in searcher function
This commit is contained in:
parent
a849fcbe68
commit
0acd713b0a
10
animal.py
10
animal.py
|
@ -402,8 +402,10 @@ class Animal(ModelSQL, ModelView, AnimalMixin):
|
|||
class AnimalTag(ModelSQL):
|
||||
'Animal - Tag'
|
||||
__name__ = 'farm.animal-farm.tag'
|
||||
animal = fields.Many2One('farm.animal', 'Animal', required=True)
|
||||
tag = fields.Many2One('farm.tag', 'Tag', required=True)
|
||||
animal = fields.Many2One('farm.animal', 'Animal', ondelete='CASCADE',
|
||||
required=True, select=True)
|
||||
tag = fields.Many2One('farm.tag', 'Tag', ondelete='CASCADE', required=True,
|
||||
select=True)
|
||||
|
||||
|
||||
class AnimalWeight(ModelSQL, ModelView):
|
||||
|
@ -612,13 +614,13 @@ class Female:
|
|||
last_farrowing_events = FarrowingEvent.search([
|
||||
('animal', '=', self),
|
||||
('state', '=', 'validated'),
|
||||
('produced_group', '!=', False),
|
||||
('produced_group', '!=', None),
|
||||
],
|
||||
order=[
|
||||
('timestamp', 'DESC'),
|
||||
], limit=1)
|
||||
if last_farrowing_events:
|
||||
return last_farrowing_events[0].produced_group
|
||||
return last_farrowing_events[0].produced_group.id
|
||||
return None
|
||||
|
||||
def get_days_from_farrowing(self, name):
|
||||
|
|
|
@ -182,12 +182,12 @@ class AnimalGroup(ModelSQL, ModelView, AnimalMixin):
|
|||
warehouses = Location.search([
|
||||
('id', 'in', specie_warehouse_ids),
|
||||
('type', '=', 'warehouse'),
|
||||
('warehouse',) + domain[1:],
|
||||
('warehouse',) + tuple(domain[1:]),
|
||||
])
|
||||
else:
|
||||
warehouses = Location.search([
|
||||
('type', '=', 'warehouse'),
|
||||
('warehouse',) + domain[1:],
|
||||
('warehouse',) + tuple(domain[1:]),
|
||||
])
|
||||
if not warehouses:
|
||||
return []
|
||||
|
@ -321,8 +321,10 @@ class AnimalGroup(ModelSQL, ModelView, AnimalMixin):
|
|||
class AnimalGroupTag(ModelSQL):
|
||||
'Animal Group - Tag'
|
||||
__name__ = 'farm.animal.group-farm.tag'
|
||||
group = fields.Many2One('farm.animal.group', 'Group', required=True)
|
||||
tag = fields.Many2One('farm.tag', 'Tag', required=True)
|
||||
group = fields.Many2One('farm.animal.group', 'Group', ondelete='CASCADE',
|
||||
required=True, select=True)
|
||||
tag = fields.Many2One('farm.tag', 'Tag', ondelete='CASCADE', required=True,
|
||||
select=True)
|
||||
|
||||
|
||||
class AnimalGroupWeight(ModelSQL, ModelView):
|
||||
|
|
|
@ -25,7 +25,7 @@ class AbortEvent(AbstractEvent):
|
|||
super(AbortEvent, cls).__setup__()
|
||||
cls.animal.domain += [
|
||||
('type', '=', 'female'),
|
||||
('current_cycle', '!=', False),
|
||||
('current_cycle', '!=', None),
|
||||
If(Equal(Eval('state'), 'draft'),
|
||||
('current_cycle.state', '=', 'pregnant'),
|
||||
()),
|
||||
|
|
|
@ -67,7 +67,7 @@ class FarrowingEvent(AbstractEvent):
|
|||
super(FarrowingEvent, cls).__setup__()
|
||||
cls.animal.domain += [
|
||||
('type', '=', 'female'),
|
||||
('current_cycle', '!=', False),
|
||||
('current_cycle', '!=', None),
|
||||
If(Equal(Eval('state'), 'draft'),
|
||||
('current_cycle.state', '=', 'pregnant'),
|
||||
()),
|
||||
|
|
|
@ -959,8 +959,10 @@ class FeedProvisionalInventoryLocation(ModelSQL):
|
|||
__name__ = 'farm.feed.provisional_inventory-stock.location'
|
||||
|
||||
inventory = fields.Many2One('farm.feed.provisional_inventory',
|
||||
'Feed Provisional Inventory', required=True)
|
||||
location = fields.Many2One('stock.location', 'Location', required=True)
|
||||
'Feed Provisional Inventory', ondelete='CASCADE', required=True,
|
||||
select=True)
|
||||
location = fields.Many2One('stock.location', 'Location', required=True,
|
||||
select=True)
|
||||
|
||||
|
||||
class FeedInventoryLine(ModelSQL, ModelView):
|
||||
|
|
|
@ -28,7 +28,7 @@ class FosterEvent(AbstractEvent):
|
|||
('type', '=', 'female'),
|
||||
('farm', '=', Eval('farm')),
|
||||
('id', '!=', Eval('animal')),
|
||||
('current_cycle', '!=', False),
|
||||
('current_cycle', '!=', None),
|
||||
If(Equal(Eval('state'), 'draft'),
|
||||
('current_cycle.state', '=', 'lactating'),
|
||||
()),
|
||||
|
@ -57,7 +57,7 @@ class FosterEvent(AbstractEvent):
|
|||
cls.animal.domain += [
|
||||
('farm', '=', Eval('farm')),
|
||||
('type', '=', 'female'),
|
||||
('current_cycle', '!=', False),
|
||||
('current_cycle', '!=', None),
|
||||
If(Equal(Eval('state'), 'draft'),
|
||||
('current_cycle.state', '=', 'lactating'),
|
||||
()),
|
||||
|
@ -115,7 +115,8 @@ class FosterEvent(AbstractEvent):
|
|||
(exchanging animal_id != pair_animal_id and
|
||||
fostered_in != fostered_out)
|
||||
'''
|
||||
Move = Pool().get('stock.move')
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
todo_moves = []
|
||||
for foster_event in events:
|
||||
assert (not foster_event.move and not foster_event.pair_event), (
|
||||
|
|
|
@ -50,7 +50,7 @@ class InseminationEvent(AbstractEvent):
|
|||
('type', '=', 'female'),
|
||||
If(Equal(Eval('state'), 'draft'),
|
||||
['OR', [
|
||||
('current_cycle', '=', False),
|
||||
('current_cycle', '=', None),
|
||||
], [
|
||||
('current_cycle.state', 'in', ('mated', 'unmated')),
|
||||
], ],
|
||||
|
|
|
@ -30,7 +30,7 @@ class PregnancyDiagnosisEvent(AbstractEvent):
|
|||
super(PregnancyDiagnosisEvent, cls).__setup__()
|
||||
cls.animal.domain += [
|
||||
('type', '=', 'female'),
|
||||
('current_cycle', '!=', False),
|
||||
('current_cycle', '!=', None),
|
||||
If(Equal(Eval('state'), 'draft'),
|
||||
('current_cycle.state', 'in', ('mated', 'pregnant')),
|
||||
()),
|
||||
|
|
|
@ -99,7 +99,7 @@ class WeaningEvent(AbstractEvent):
|
|||
('farm', '=', Eval('farm')),
|
||||
('location.type', '=', 'storage'),
|
||||
('type', '=', 'female'),
|
||||
('current_cycle', '!=', False),
|
||||
('current_cycle', '!=', None),
|
||||
If(Equal(Eval('state'), 'draft'),
|
||||
('current_cycle.state', '=', 'lactating'),
|
||||
()),
|
||||
|
|
|
@ -641,8 +641,9 @@ class SpecieModel(ModelSQL):
|
|||
'Specie - Model'
|
||||
__name__ = 'farm.specie-ir.model'
|
||||
_table = 'farm_specie_ir_model'
|
||||
specie = fields.Many2One('farm.specie', 'Specie', required=True)
|
||||
model = fields.Many2One('ir.model', 'Model', required=True)
|
||||
specie = fields.Many2One('farm.specie', 'Specie', ondelete='CASCADE',
|
||||
required=True, select=True)
|
||||
model = fields.Many2One('ir.model', 'Model', required=True, select=True)
|
||||
|
||||
|
||||
class Menu(ModelSQL, ModelView):
|
||||
|
|
18
stock.py
18
stock.py
|
@ -85,9 +85,9 @@ class LotAnimal(ModelSQL):
|
|||
__name__ = 'stock.lot-farm.animal'
|
||||
|
||||
lot = fields.Many2One('stock.lot', 'Lot', required=True,
|
||||
ondelete='RESTRICT')
|
||||
ondelete='RESTRICT', select=True)
|
||||
animal = fields.Many2One('farm.animal', 'Animal', required=True,
|
||||
ondelete='RESTRICT')
|
||||
ondelete='RESTRICT', select=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -103,9 +103,9 @@ class LotAnimalGroup(ModelSQL):
|
|||
__name__ = 'stock.lot-farm.animal.group'
|
||||
|
||||
lot = fields.Many2One('stock.lot', 'Lot', required=True,
|
||||
ondelete='RESTRICT')
|
||||
ondelete='RESTRICT', select=True)
|
||||
animal_group = fields.Many2One('farm.animal.group', 'Animal Group',
|
||||
required=True, ondelete='RESTRICT')
|
||||
required=True, ondelete='RESTRICT', select=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -184,7 +184,7 @@ class Location:
|
|||
|
||||
@classmethod
|
||||
def search(cls, args, offset=0, limit=None, order=None, count=False,
|
||||
query_string=False):
|
||||
query=False):
|
||||
FarmLine = Pool().get('farm.specie.farm_line')
|
||||
|
||||
args = args[:]
|
||||
|
@ -209,7 +209,7 @@ class Location:
|
|||
],
|
||||
]]
|
||||
res = super(Location, cls).search(args, offset=offset, limit=limit,
|
||||
order=order, count=count, query_string=query_string)
|
||||
order=order, count=count, query=query)
|
||||
return res
|
||||
|
||||
def get_lot_fifo(self, stock_date=None, to_uom=None):
|
||||
|
@ -310,8 +310,10 @@ class Location:
|
|||
class LocationSiloLocation(ModelSQL):
|
||||
'Silo - Location'
|
||||
__name__ = 'stock.location.silo-stock.location'
|
||||
silo = fields.Many2One('stock.location', 'Silo', required=True)
|
||||
location = fields.Many2One('stock.location', 'Location', required=True)
|
||||
silo = fields.Many2One('stock.location', 'Silo', ondelete='CASCADE',
|
||||
required=True, select=True)
|
||||
location = fields.Many2One('stock.location', 'Location',
|
||||
ondelete='CASCADE', required=True, select=True)
|
||||
|
||||
|
||||
class Move:
|
||||
|
|
6
user.py
6
user.py
|
@ -26,5 +26,7 @@ class User:
|
|||
class UserLocation(ModelSQL):
|
||||
'User - Location'
|
||||
__name__ = 'res.user-stock.location'
|
||||
user = fields.Many2One('res.user', 'User', required=True)
|
||||
location = fields.Many2One('stock.location', 'Location', required=True)
|
||||
user = fields.Many2One('res.user', 'User', ondelete='CASCADE',
|
||||
required=True, select=True)
|
||||
location = fields.Many2One('stock.location', 'Location',
|
||||
ondelete='CASCADE', required=True, select=True)
|
||||
|
|
Loading…
Reference in New Issue