Refactory crop stages
This commit is contained in:
parent
a86b3244eb
commit
e6c7fc5c8a
14
__init__.py
14
__init__.py
|
@ -25,22 +25,22 @@ def register():
|
|||
sale.AduanaDetailedStart,
|
||||
crop.Kind,
|
||||
crop.Activity,
|
||||
crop.CropActivity,
|
||||
crop.CropActivitySupply,
|
||||
crop.FarmingVariety,
|
||||
crop.FarmingVarietyActivity,
|
||||
crop.FarmingActivitySupply,
|
||||
crop.Variety,
|
||||
crop.VarietyStage,
|
||||
crop.VarietyStageActivity,
|
||||
crop.VarietyStageActivitySupply,
|
||||
crop.FarmingActivityShipmentInternal,
|
||||
crop.FarmingStage,
|
||||
crop.FarmingCrop,
|
||||
crop.Crop,
|
||||
crop.CropStage,
|
||||
crop.CropStageActivity,
|
||||
crop.CropStageActivitySupply,
|
||||
crop.FarmingCropLot,
|
||||
crop.FarmingCropLotBed,
|
||||
crop.CropForecastStart,
|
||||
crop.CropForecastWeekStart,
|
||||
crop.CropActivitiesStart,
|
||||
crop.CropSuppliesStart,
|
||||
crop.FarmingVarietyCycle,
|
||||
crop.SupplyMoves,
|
||||
location.FarmingLocationLotBed,
|
||||
location.FarmingLocationLot,
|
||||
|
|
392
crop.py
392
crop.py
|
@ -26,29 +26,16 @@ class FarmingStage(ModelSQL, ModelView):
|
|||
name = fields.Char('Name', required=True)
|
||||
|
||||
|
||||
class FarmingVarietyCycle(ModelSQL, ModelView):
|
||||
"Farming Variety Cycle"
|
||||
__name__ = "farming.variety.cycle"
|
||||
variety = fields.Many2One('farming.variety', 'Variety')
|
||||
lot = fields.Many2One('farming.location.lot', 'Lot')
|
||||
sequence = fields.Integer('Sequence', required=True)
|
||||
stage = fields.Many2One('farming.stage', 'Stage', required=True)
|
||||
start_time = fields.Integer('Start Time', help='Harvest week',
|
||||
required=True)
|
||||
production_rate = fields.Float('Production Rate', digits=(3, 2))
|
||||
|
||||
|
||||
class FarmingVariety(ModelSQL, ModelView):
|
||||
'Farming Variety'
|
||||
class Variety(ModelSQL, ModelView):
|
||||
'Variety'
|
||||
__name__ = 'farming.variety'
|
||||
product = fields.Many2One('product.product', 'Product', required=True)
|
||||
production_rate = fields.Float('Production Rate', digits=(16, 2))
|
||||
production_uom = fields.Many2One('product.uom', 'UoM')
|
||||
standard_cycle = fields.Integer('Standard Cycle', help='In weeks')
|
||||
activities = fields.One2Many('farming.variety.activity', 'variety',
|
||||
'Activities')
|
||||
stages = fields.One2Many('farming.variety.stage', 'variety', 'Stages')
|
||||
location = fields.Many2One('farming.location', 'Location')
|
||||
cycles = fields.One2Many('farming.variety.cycle', 'variety', 'Cycles')
|
||||
# cycles = fields.One2Many('farming.variety.cycle', 'variety', 'Cycles')
|
||||
|
||||
def get_rec_name(self, name=None):
|
||||
if self.location:
|
||||
|
@ -57,22 +44,59 @@ class FarmingVariety(ModelSQL, ModelView):
|
|||
return self.product.template.name
|
||||
|
||||
|
||||
class FarmingActivitySupply(ModelSQL, ModelView):
|
||||
'Farming Activity Supply'
|
||||
__name__ = 'farming.variety.activity.supply'
|
||||
activity = fields.Many2One('farming.variety.activity', 'Activity')
|
||||
class VarietyStage(ModelSQL, ModelView):
|
||||
"Variety Stage"
|
||||
__name__ = "farming.variety.stage"
|
||||
variety = fields.Many2One('farming.variety', 'Variety')
|
||||
lot = fields.Many2One('farming.location.lot', 'Lot')
|
||||
sequence = fields.Integer('Sequence', required=True)
|
||||
stage = fields.Many2One('farming.stage', 'Stage', required=True)
|
||||
start_time = fields.Integer('Start Time', help='Harvest week',
|
||||
required=True)
|
||||
production_rate = fields.Float('Production Rate', digits=(3, 2))
|
||||
activities = fields.One2Many('farming.variety.stage.activity', 'stage',
|
||||
'Activities')
|
||||
|
||||
|
||||
class VarietyStageActivity(ModelSQL, ModelView):
|
||||
'Variety Stage Activity'
|
||||
# 'farming.variety.activity' => 'farming.variety.stage.activity'
|
||||
__name__ = 'farming.variety.stage.activity'
|
||||
# variety = fields.Many2One('farming.variety', 'Variety')
|
||||
stage = fields.Many2One('farming.variety.stage', 'Stage')
|
||||
sequence = fields.Integer('Sequence', required=True)
|
||||
kind = fields.Many2One('farming.activity.kind', 'Kind', required=True)
|
||||
work_time = fields.Numeric('Work Time', required=True)
|
||||
cost_per_hour = fields.Numeric('Cost Per Hour', digits=(16, 2))
|
||||
uom = fields.Many2One('product.uom', 'Unit')
|
||||
uom_time = fields.Many2One('product.uom', 'Unit of Time')
|
||||
supplies = fields.One2Many('farming.variety.stage.activity.supply',
|
||||
'activity', 'Supply')
|
||||
time_of_realization = fields.Integer('Time of Realization', required=True,
|
||||
help='In weeks')
|
||||
|
||||
@fields.depends('kind', 'uom')
|
||||
def on_change_kind(self):
|
||||
if self.kind:
|
||||
self.uom = self.kind.uom.id
|
||||
|
||||
|
||||
class VarietyStageActivitySupply(ModelSQL, ModelView):
|
||||
'Variety Stage Activity Supply'
|
||||
__name__ = 'farming.variety.stage.activity.supply'
|
||||
# farming.variety.activity.supply => farming.variety.stage.activity.supply
|
||||
activity = fields.Many2One('farming.variety.stage.activity', 'Activity')
|
||||
product = fields.Many2One("product.product", "Product", required=True)
|
||||
quantity = fields.Float('Quantity', required=True)
|
||||
unit = fields.Many2One('product.uom', 'Unit',
|
||||
domain=[
|
||||
unit = fields.Many2One('product.uom', 'Unit', domain=[
|
||||
If(Bool(Eval('product_uom_category')),
|
||||
('category', '=', Eval('product_uom_category')),
|
||||
('category', '!=', -1)),
|
||||
],
|
||||
depends=['product_uom_category'])
|
||||
product_uom_category = fields.Function(
|
||||
fields.Many2One('product.uom.category', 'Product Uom Category'),
|
||||
], depends=['product_uom_category'])
|
||||
product_uom_category = fields.Function(fields.Many2One(
|
||||
'product.uom.category', 'Product Uom Category'),
|
||||
'on_change_with_product_uom_category')
|
||||
unit_price = fields.Numeric('Unit Price', digits=(16, 2))
|
||||
|
||||
@fields.depends('product')
|
||||
def on_change_with_unit(self, name=None):
|
||||
|
@ -88,43 +112,21 @@ class FarmingActivitySupply(ModelSQL, ModelView):
|
|||
return None
|
||||
|
||||
|
||||
class FarmingVarietyActivity(ModelSQL, ModelView):
|
||||
'Farming Variety Activity'
|
||||
__name__ = 'farming.variety.activity'
|
||||
variety = fields.Many2One('farming.variety', 'Variety')
|
||||
sequence = fields.Integer('Sequence', required=True)
|
||||
kind = fields.Many2One('farming.activity.kind', 'Kind', required=True)
|
||||
work_time = fields.Numeric('Work Time', required=True)
|
||||
cost_per_hour = fields.Numeric('Cost Per Hour', digits=(16, 2))
|
||||
uom = fields.Many2One('product.uom', 'Unit')
|
||||
uom_time = fields.Many2One('product.uom', 'Unit of Time')
|
||||
supplies = fields.One2Many('farming.variety.activity.supply', 'activity',
|
||||
'Supply')
|
||||
time_of_realization = fields.Integer('Time of Realization', required=True,
|
||||
help='In weeks')
|
||||
|
||||
@fields.depends('kind', 'uom')
|
||||
def on_change_kind(self):
|
||||
if self.kind:
|
||||
self.uom = self.kind.uom.id
|
||||
|
||||
|
||||
class CropStage(ModelSQL, ModelView):
|
||||
"Crop Stage"
|
||||
__name__ = "farming.crop.stage"
|
||||
crop = fields.Many2One('farming.crop', 'Crop', required=True)
|
||||
activity = fields.Many2One('farming.crop.activity', 'Activity',
|
||||
states={"invisible": False})
|
||||
stage = fields.Many2One('farming.stage', 'Stage', required=True)
|
||||
week = fields.Float('Week', required=True)
|
||||
effective_date = fields.Date('Effective Date')
|
||||
analytic_account = fields.Many2One('analytic_account.account',
|
||||
'Analytic Account')
|
||||
activities = fields.One2Many('farming.crop.activity', 'stage', 'Activity')
|
||||
activities = fields.One2Many('farming.crop.stage.activity', 'stage',
|
||||
'Activity')
|
||||
production_rate = fields.Float('Production Rate', digits=(3, 2))
|
||||
quantity_planned = fields.Function(fields.Float('Qty. Planned',
|
||||
digits=(6, 2)), 'get_quantity_planned')
|
||||
quantity_produced = fields.Float('Qty. Produced', digits=(6, 2))
|
||||
# analytic_account = fields.Many2One('analytic_account.account',
|
||||
# 'Analytic Account')
|
||||
|
||||
def get_quantity_planned(self, name=None):
|
||||
res = 0
|
||||
|
@ -142,7 +144,7 @@ class Kind(ModelSQL, ModelView):
|
|||
help="Unit of time, according to activity time")
|
||||
|
||||
|
||||
class FarmingCrop(Workflow, ModelSQL, ModelView):
|
||||
class Crop(Workflow, ModelSQL, ModelView):
|
||||
'Farming Crop'
|
||||
__name__ = 'farming.crop'
|
||||
_rec_name = 'number'
|
||||
|
@ -167,7 +169,6 @@ class FarmingCrop(Workflow, ModelSQL, ModelView):
|
|||
lots = fields.One2Many('farming.crop.lot', 'crop', 'Lots', states=STATES)
|
||||
stages = fields.One2Many('farming.crop.stage', 'crop', 'Stages',
|
||||
states=STATES)
|
||||
activities = fields.One2Many('farming.crop.activity', 'crop', 'Activities')
|
||||
seed = fields.Many2One('farming.seed', 'Seed', required=True)
|
||||
analytic_account = fields.Many2One('analytic_account.account', 'Analytic Account')
|
||||
production_rate = fields.Float('Production Rate')
|
||||
|
@ -179,7 +180,8 @@ class FarmingCrop(Workflow, ModelSQL, ModelView):
|
|||
('cancelled', 'Cancelled'),
|
||||
], 'State', readonly=True, required=True)
|
||||
# moves for supplies
|
||||
supplies = fields.One2Many('farming.crop.activity.supply', 'crop', 'Supply')
|
||||
# supplies = fields.One2Many('farming.crop.stage.activity.supply',
|
||||
# 'crop', 'Supply')
|
||||
# Financial indicators
|
||||
production_time = fields.Function(fields.Integer('Production Time'),
|
||||
'get_production_time')
|
||||
|
@ -191,10 +193,12 @@ class FarmingCrop(Workflow, ModelSQL, ModelView):
|
|||
'get_gross_profit_rate')
|
||||
gross_profit = fields.Function(fields.Numeric('Gross Profit'),
|
||||
'get_gross_profit')
|
||||
# Deprecation warning: activities was moved to farming.crop.stage
|
||||
# activities = fields.One2Many('farming.crop.activity', 'crop', 'Activities')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(FarmingCrop, cls).__setup__()
|
||||
super(Crop, cls).__setup__()
|
||||
cls._order.insert(0, ('create_date', 'DESC'))
|
||||
cls._order.insert(1, ('id', 'DESC'))
|
||||
cls._transitions |= set((
|
||||
|
@ -210,7 +214,7 @@ class FarmingCrop(Workflow, ModelSQL, ModelView):
|
|||
'cancel': {
|
||||
'invisible': Eval('state') == 'finished',
|
||||
},
|
||||
'load_activities': {
|
||||
'load_stages': {
|
||||
'invisible': Eval('lines', []) | (Eval('state') != 'draft'),
|
||||
'depends': ['state'],
|
||||
},
|
||||
|
@ -320,82 +324,133 @@ class FarmingCrop(Workflow, ModelSQL, ModelView):
|
|||
lines_to_delete.append(lot)
|
||||
Line.delete(lines_to_delete)
|
||||
|
||||
@classmethod
|
||||
def create_stages_lines(cls, crops):
|
||||
Line = Pool().get('farming.crop.stage')
|
||||
lines = []
|
||||
cls.clear_stages_lines(crops)
|
||||
for crop in crops:
|
||||
for stage in crop.variety.cycles:
|
||||
effective_date = crop.start_date + timedelta(weeks=stage.start_time)
|
||||
line = Line(
|
||||
crop=crop.id,
|
||||
stage=stage.stage.id,
|
||||
production_rate=stage.production_rate,
|
||||
week=stage.start_time,
|
||||
effective_date=effective_date,
|
||||
)
|
||||
lines.append(line)
|
||||
Line.save(lines)
|
||||
def _create_supplies(self, activity, crop_activity):
|
||||
Supply = Pool().get('farming.crop.stage.activity.supply')
|
||||
res = []
|
||||
for sup in activity.supplies:
|
||||
unit_price = sup.unit_price
|
||||
if not unit_price:
|
||||
unit_price = sup.product.cost_price
|
||||
qty = sup.quantity * self.total_plants
|
||||
amount = round(qty * float(unit_price), 2)
|
||||
supply = Supply(
|
||||
activity=crop_activity.id,
|
||||
product=sup.product.id,
|
||||
unit=sup.unit.id,
|
||||
unit_price=unit_price,
|
||||
quantity=qty,
|
||||
cost_planned=amount,
|
||||
cost_real=amount
|
||||
)
|
||||
res.append(supply)
|
||||
return res
|
||||
|
||||
def _create_activities(self, stage, crop_stage):
|
||||
Activity = Pool().get('farming.crop.stage.activity')
|
||||
res = []
|
||||
crop = crop_stage.crop
|
||||
for act in stage.activities:
|
||||
_date = crop.start_date + timedelta(weeks=act.time_of_realization)
|
||||
work_time = act.work_time * crop.total_plants
|
||||
# if act.uom_time.symbol == 'min':
|
||||
# _cost = round((act.cost_per_hour / 60) * work_time, 2)
|
||||
# elif act.uom_time.symbol == 'h':
|
||||
# _cost = round(act.cost_per_hour * work_time, 2)
|
||||
# elif act.uom_time.symbol == 's':
|
||||
# _cost = round((act.cost_per_hour / 3600) * work_time, 2)
|
||||
# else:
|
||||
# _cost = round(act.cost_per_hour * work_time, 2)
|
||||
|
||||
activity = Activity(
|
||||
stage=crop_stage.id,
|
||||
sequence=act.sequence,
|
||||
kind=act.kind.id,
|
||||
work_time=work_time,
|
||||
uom_time=act.uom_time.id,
|
||||
week=act.time_of_realization,
|
||||
planned_date=_date,
|
||||
effective_date=_date,
|
||||
)
|
||||
supplies = self._create_supplies(act, activity)
|
||||
activity.supplies = supplies
|
||||
res.append(activity)
|
||||
return res
|
||||
|
||||
def create_stages(self):
|
||||
CropStage = Pool().get('farming.crop.stage')
|
||||
to_save = []
|
||||
for stage in self.variety.stages:
|
||||
effec_date = self.start_date + timedelta(weeks=stage.start_time)
|
||||
_stage = CropStage(
|
||||
crop=self.id,
|
||||
stage=stage.stage.id,
|
||||
production_rate=stage.production_rate,
|
||||
week=stage.start_time,
|
||||
effective_date=effec_date,
|
||||
)
|
||||
_stage.activities = self._create_activities(stage, _stage)
|
||||
to_save.append(_stage)
|
||||
CropStage.save(to_save)
|
||||
|
||||
@classmethod
|
||||
def clear_stages_lines(cls, crops):
|
||||
Line = Pool().get('farming.crop.stage')
|
||||
lines_to_delete = []
|
||||
to_delete = []
|
||||
for crop in crops:
|
||||
for stage in crop.stages:
|
||||
lines_to_delete.append(stage)
|
||||
Line.delete(lines_to_delete)
|
||||
to_delete.append(stage)
|
||||
Line.delete(to_delete)
|
||||
|
||||
@classmethod
|
||||
def clear_activities_lines(cls, crops):
|
||||
Line = Pool().get('farming.crop.activity')
|
||||
lines_to_delete = []
|
||||
for crop in crops:
|
||||
for activity in crop.activities:
|
||||
lines_to_delete.append(activity)
|
||||
Line.delete(lines_to_delete)
|
||||
# @classmethod
|
||||
# def clear_activities_lines(cls, crops):
|
||||
# Line = Pool().get('farming.crop.stage.activity')
|
||||
# lines_to_delete = []
|
||||
# for crop in crops:
|
||||
# for activity in crop.activities:
|
||||
# lines_to_delete.append(activity)
|
||||
# Line.delete(lines_to_delete)
|
||||
|
||||
@classmethod
|
||||
def create_activities_lines(cls, crops):
|
||||
Line = Pool().get('farming.crop.activity')
|
||||
lines = []
|
||||
for crop in crops:
|
||||
for act in crop.variety.activities:
|
||||
_date = crop.start_date + timedelta(
|
||||
weeks=act.time_of_realization)
|
||||
work_time = act.work_time * crop.total_plants
|
||||
if act.uom_time.symbol == 'min':
|
||||
_cost = round((act.cost_per_hour / 60) * work_time, 2)
|
||||
elif act.uom_time.symbol == 'h':
|
||||
_cost = round(act.cost_per_hour * work_time, 2)
|
||||
elif act.uom_time.symbol == 's':
|
||||
_cost = round((act.cost_per_hour / 3600) * work_time, 2)
|
||||
else:
|
||||
_cost = round(act.cost_per_hour * work_time, 2)
|
||||
|
||||
line = Line(
|
||||
crop=crop.id,
|
||||
sequence=act.sequence,
|
||||
kind=act.kind.id,
|
||||
work_time=work_time,
|
||||
workforce_cost=_cost,
|
||||
uom=act.uom.id,
|
||||
uom_time=act.uom_time.id,
|
||||
week=act.time_of_realization,
|
||||
planned_date=_date,
|
||||
effective_date=_date,
|
||||
)
|
||||
lines.append(line)
|
||||
Line.save(lines)
|
||||
cls.create_activity_supplies_lines(crops)
|
||||
# @classmethod
|
||||
# def create_activities_lines(cls, crops):
|
||||
# Line = Pool().get('farming.crop.activity')
|
||||
# lines = []
|
||||
# for crop in crops:
|
||||
# for act in crop.variety.activities:
|
||||
# _date = crop.start_date + timedelta(
|
||||
# weeks=act.time_of_realization)
|
||||
# work_time = act.work_time * crop.total_plants
|
||||
# if act.uom_time.symbol == 'min':
|
||||
# _cost = round((act.cost_per_hour / 60) * work_time, 2)
|
||||
# elif act.uom_time.symbol == 'h':
|
||||
# _cost = round(act.cost_per_hour * work_time, 2)
|
||||
# elif act.uom_time.symbol == 's':
|
||||
# _cost = round((act.cost_per_hour / 3600) * work_time, 2)
|
||||
# else:
|
||||
# _cost = round(act.cost_per_hour * work_time, 2)
|
||||
#
|
||||
# line = Line(
|
||||
# crop=crop.id,
|
||||
# sequence=act.sequence,
|
||||
# kind=act.kind.id,
|
||||
# work_time=work_time,
|
||||
# workforce_cost=_cost,
|
||||
# uom=act.uom.id,
|
||||
# uom_time=act.uom_time.id,
|
||||
# week=act.time_of_realization,
|
||||
# planned_date=_date,
|
||||
# effective_date=_date,
|
||||
# )
|
||||
# lines.append(line)
|
||||
# Line.save(lines)
|
||||
# cls.create_activity_supplies_lines(crops)
|
||||
|
||||
@classmethod
|
||||
def create_activity_supplies_lines(cls, crops):
|
||||
Line = Pool().get('farming.crop.activity.supply')
|
||||
Line = Pool().get('farming.crop.stage.activity.supply')
|
||||
lines = []
|
||||
for crop in crops:
|
||||
for act_crop, act_variety in zip(crop.activities, crop.variety.activities):
|
||||
for act_crop, act_variety in zip(
|
||||
crop.activities, crop.variety.activities):
|
||||
for supply in act_variety.supplies:
|
||||
line = Line(
|
||||
activity=act_crop.id,
|
||||
|
@ -413,9 +468,10 @@ class FarmingCrop(Workflow, ModelSQL, ModelView):
|
|||
Line = Pool().get('farming.crop.lot.bed')
|
||||
lines_to_delete = []
|
||||
for crop in crops:
|
||||
for activity in crop.activities:
|
||||
for supply in activity.supplies:
|
||||
lines_to_delete.append(supply)
|
||||
for stage in crop.stages:
|
||||
for activity in stage.activities:
|
||||
for supply in activity.supplies:
|
||||
lines_to_delete.append(supply)
|
||||
Line.delete(lines_to_delete)
|
||||
|
||||
@classmethod
|
||||
|
@ -432,12 +488,14 @@ class FarmingCrop(Workflow, ModelSQL, ModelView):
|
|||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def load_activities(cls, crops):
|
||||
def load_stages(cls, crops):
|
||||
cls.clear_stages_lines(crops)
|
||||
cls.create_stages_lines(crops)
|
||||
cls.clear_supplies_lines(crops)
|
||||
cls.clear_activities_lines(crops)
|
||||
cls.create_activities_lines(crops)
|
||||
for crop in crops:
|
||||
crop.create_stages()
|
||||
# cls.clear_stages_lines(crops)
|
||||
# cls.clear_supplies_lines(crops)
|
||||
# cls.clear_activities_lines(crops)
|
||||
# cls.create_activities_lines(crops)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
@ -510,7 +568,7 @@ class FarmingCrop(Workflow, ModelSQL, ModelView):
|
|||
if self.stages:
|
||||
res = []
|
||||
for stage in self.stages:
|
||||
res.append(stage.quantity_produced)
|
||||
res.append(stage.quantity_produced or 0)
|
||||
self.quantity_produced = sum(res)
|
||||
|
||||
@fields.depends('variety', 'production_uom', 'production_rate')
|
||||
|
@ -595,20 +653,19 @@ class FarmingCropLotBed(ModelSQL, ModelView):
|
|||
quantity_plants = fields.Integer('Quantity Plants')
|
||||
|
||||
|
||||
class CropActivity(Workflow, ModelSQL, ModelView):
|
||||
'Crop Activity'
|
||||
__name__ = 'farming.crop.activity'
|
||||
crop = fields.Many2One('farming.crop', 'Crop', ondelete='CASCADE',
|
||||
required=True)
|
||||
stage = fields.Many2One('farming.crop.stage', 'Stage')
|
||||
class CropStageActivity(Workflow, ModelSQL, ModelView):
|
||||
'Crop Stage Activity'
|
||||
# farming.crop.activity => farming.crop.stage.activity
|
||||
__name__ = 'farming.crop.stage.activity'
|
||||
# crop = fields.Many2One('farming.crop', 'Crop', ondelete='CASCADE')
|
||||
stage = fields.Many2One('farming.crop.stage', 'Stage', ondelete='CASCADE')
|
||||
sequence = fields.Char('Sequence', states=STATES)
|
||||
kind = fields.Many2One('farming.activity.kind', 'Kind')
|
||||
work_time = fields.Numeric('Work Time')
|
||||
workforce_cost = fields.Numeric('Workforce Cost', digits=(16, 2))
|
||||
uom = fields.Many2One('product.uom', 'Unit')
|
||||
# uom = fields.Many2One('product.uom', 'Unit')
|
||||
uom_time = fields.Many2One('product.uom', 'UoM of Time')
|
||||
supplies = fields.One2Many('farming.crop.activity.supply', 'activity',
|
||||
'Supply')
|
||||
supplies = fields.One2Many('farming.crop.stage.activity.supply',
|
||||
'activity', 'Supply')
|
||||
week = fields.Integer('Week')
|
||||
planned_date = fields.Date('Planned Date')
|
||||
effective_date = fields.Date('Effective Date')
|
||||
|
@ -618,12 +675,20 @@ class CropActivity(Workflow, ModelSQL, ModelView):
|
|||
('finished', 'Finished'),
|
||||
('cancelled', 'Cancelled'),
|
||||
], 'State', readonly=True, required=True)
|
||||
workforce_cost = fields.Function(fields.Numeric(
|
||||
'Workforce Cost', digits=(16, 2)), 'get_cost')
|
||||
materials_cost = fields.Function(fields.Numeric(
|
||||
'Materials Cost', digits=(16, 2)), 'get_cost')
|
||||
indirect_cost = fields.Function(fields.Numeric(
|
||||
'Indirect Cost', digits=(16, 2)), 'get_cost')
|
||||
total_cost = fields.Function(fields.Numeric(
|
||||
'Total Cost', digits=(16, 2)), 'get_cost')
|
||||
|
||||
@classmethod
|
||||
def generate_shipment(cls, records):
|
||||
pool = Pool()
|
||||
company = Transaction().context.get('company')
|
||||
Supply = pool.get('farming.crop.activity.supply')
|
||||
Supply = pool.get('farming.crop.stage.activity.supply')
|
||||
supplies = []
|
||||
for record in records:
|
||||
location = record.crop.location.warehouse
|
||||
|
@ -634,14 +699,14 @@ class CropActivity(Workflow, ModelSQL, ModelView):
|
|||
unit=supplyRec.unit,
|
||||
quantity=supplyRec.quantity,
|
||||
)
|
||||
move = record._move(
|
||||
record,
|
||||
location.output_location,
|
||||
location.production_location,
|
||||
company,
|
||||
supplyRec.product,
|
||||
supplyRec.unit,
|
||||
supplyRec.quantity)
|
||||
# move = record._move(
|
||||
# record,
|
||||
# location.output_location,
|
||||
# location.production_location,
|
||||
# company,
|
||||
# supplyRec.product,
|
||||
# supplyRec.unit,
|
||||
# supplyRec.quantity)
|
||||
supplies.append(supply)
|
||||
Supply.save(supplies)
|
||||
|
||||
|
@ -666,6 +731,15 @@ class CropActivity(Workflow, ModelSQL, ModelView):
|
|||
Move.save([move])
|
||||
return move
|
||||
|
||||
def get_cost(self, name=None):
|
||||
res = []
|
||||
for supply in self.supplies:
|
||||
_name, _name_cost = name.split('_')
|
||||
print(name, _name, _name_cost)
|
||||
if supply.product.template.cost_type == _name or _name == 'total':
|
||||
res.append(supply.cost_planned)
|
||||
return sum(res)
|
||||
|
||||
@classmethod
|
||||
def create_supply_moves(cls, location):
|
||||
# pool = Pool()
|
||||
|
@ -697,7 +771,7 @@ class CropActivity(Workflow, ModelSQL, ModelView):
|
|||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(CropActivity, cls).__setup__()
|
||||
super(CropStageActivity, cls).__setup__()
|
||||
cls._order.insert(0, ('planned_date', 'ASC'))
|
||||
cls._transitions |= set((
|
||||
('draft', 'production'),
|
||||
|
@ -800,24 +874,26 @@ class CropActivity(Workflow, ModelSQL, ModelView):
|
|||
pass
|
||||
|
||||
|
||||
class CropActivitySupply(ModelSQL, ModelView):
|
||||
'Crop Activity Supply'
|
||||
__name__ = 'farming.crop.activity.supply'
|
||||
crop = fields.Many2One('farming.crop', 'Crop')
|
||||
activity = fields.Many2One('farming.crop.activity', 'Activity',
|
||||
class CropStageActivitySupply(ModelSQL, ModelView):
|
||||
'Crop Stage Activity Supply'
|
||||
# farming.crop.activity.supply => farming.crop.stage.activity.supply
|
||||
__name__ = 'farming.crop.stage.activity.supply'
|
||||
# crop = fields.Many2One('farming.crop', 'Crop')
|
||||
activity = fields.Many2One('farming.crop.stage.activity', 'Activity',
|
||||
states={"invisible": False})
|
||||
product = fields.Many2One("product.product", "Product", required=True,
|
||||
select=True)
|
||||
unit = fields.Many2One('product.uom', 'Unit')
|
||||
quantity = fields.Float('Quantity', required=True)
|
||||
unit_price = fields.Numeric('Unit Price')
|
||||
analytic_account = fields.Many2One('analytic_account.account',
|
||||
'Analytic Account')
|
||||
cost_planned = fields.Numeric('Cost Planned', readonly=True)
|
||||
cost_real = fields.Numeric('Cost Real')
|
||||
|
||||
def get_unity(self, name=None):
|
||||
unity = self.product.default_uom.name
|
||||
return unity
|
||||
# def get_unit(self, name=None):
|
||||
# unit = self.product.default_uom.name
|
||||
# return unit
|
||||
|
||||
|
||||
class Activity(Workflow, ModelSQL, ModelView):
|
||||
|
|
52
crop.xml
52
crop.xml
|
@ -25,15 +25,15 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="name">farming_stage_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="farming_variety_cycle_view_tree">
|
||||
<field name="model">farming.variety.cycle</field>
|
||||
<record model="ir.ui.view" id="farming_variety_stage_view_tree">
|
||||
<field name="model">farming.variety.stage</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">variety_cycle_tree</field>
|
||||
<field name="name">variety_stage_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="farming_variety_cycle_view_form">
|
||||
<field name="model">farming.variety.cycle</field>
|
||||
<record model="ir.ui.view" id="farming_variety_stage_view_form">
|
||||
<field name="model">farming.variety.stage</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">variety_cycle_form</field>
|
||||
<field name="name">variety_stage_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="farming_variety_view_tree">
|
||||
|
@ -64,20 +64,20 @@ this repository contains the full copyright notices and license terms. -->
|
|||
action="act_farming_variety_tree" id="menu_farming_variety_tree"/>
|
||||
|
||||
<record model="ir.ui.view" id="farming_variety_activity_supply_view_tree">
|
||||
<field name="model">farming.variety.activity.supply</field>
|
||||
<field name="model">farming.variety.stage.activity.supply</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">farming_activity_supply_tree</field>
|
||||
<field name="name">variety_activity_stage_supply_tree</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="farming_variety_activity_view_tree">
|
||||
<field name="model">farming.variety.activity</field>
|
||||
<record model="ir.ui.view" id="farming_variety_stage_activity_view_tree">
|
||||
<field name="model">farming.variety.stage.activity</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">variety_activity_tree</field>
|
||||
<field name="name">variety_stage_activity_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="farming_variety_activity_form">
|
||||
<field name="model">farming.variety.activity</field>
|
||||
<record model="ir.ui.view" id="farming_variety_stage_activity_form">
|
||||
<field name="model">farming.variety.stage.activity</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">variety_activity_form</field>
|
||||
<field name="name">variety_stage_activity_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="farming_activity_kind_view_tree">
|
||||
|
@ -187,26 +187,26 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="name">farming_crop_lot_bed_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="farming_crop_activity_view_tree">
|
||||
<field name="model">farming.crop.activity</field>
|
||||
<record model="ir.ui.view" id="farming_crop_stage_activity_view_tree">
|
||||
<field name="model">farming.crop.stage.activity</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">farming_crop_activity_tree</field>
|
||||
<field name="name">crop_stage_activity_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="farming_crop_activity_view_form">
|
||||
<field name="model">farming.crop.activity</field>
|
||||
<record model="ir.ui.view" id="farming_crop_stage_activity_view_form">
|
||||
<field name="model">farming.crop.stage.activity</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">farming_crop_activity_form</field>
|
||||
<field name="name">crop_stage_activity_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="farming_crop_supply_view_tree">
|
||||
<field name="model">farming.crop.activity.supply</field>
|
||||
<record model="ir.ui.view" id="farming_crop_activity_stage_supply_view_tree">
|
||||
<field name="model">farming.crop.stage.activity.supply</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">farming_crop_supply_tree</field>
|
||||
<field name="name">crop_stage_activity_supply_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="farming_crop_supply_view_form">
|
||||
<field name="model">farming.crop.activity.supply</field>
|
||||
<record model="ir.ui.view" id="farming_crop_activity_stage_supply_view_form">
|
||||
<field name="model">farming.crop.stage.activity.supply</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">farming_crop_supply_form</field>
|
||||
<field name="name">crop_stage_activity_supply_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="activity_view_tree">
|
||||
|
|
19
patch.sql
19
patch.sql
|
@ -1,9 +1,16 @@
|
|||
|
||||
DROP TABLE farming_production_crop;
|
||||
DROP TABLE farming_production_work;
|
||||
DROP TABLE farming_production;
|
||||
-- DROP TABLE farming_production_crop;
|
||||
-- DROP TABLE farming_production_work;
|
||||
-- DROP TABLE farming_production;
|
||||
--
|
||||
--
|
||||
-- ALTER TABLE farming_crop_lot DROP COLUMN number;
|
||||
-- ALTER TABLE farming_crop_lot_bed DROP COLUMN code;
|
||||
-- ALTER TABLE farming_crop_stage DROP COLUMN activity_time;
|
||||
|
||||
|
||||
ALTER TABLE farming_crop_lot DROP COLUMN number;
|
||||
ALTER TABLE farming_crop_lot_bed DROP COLUMN code;
|
||||
ALTER TABLE farming_crop_stage DROP COLUMN activity_time;
|
||||
-- DROP TABLE farming_variety_stage CASCADE;
|
||||
|
||||
ALTER TABLE farming_variety_cycle RENAME TO farming_variety_stage;
|
||||
ALTER TABLE farming_crop_activity RENAME TO farming_crop_stage_activity;
|
||||
ALTER TABLE farming_crop_activity_supply RENAME TO farming_crop_stage_activity_supply;
|
||||
|
|
|
@ -14,3 +14,9 @@ class ProductStyle(ModelSQL, ModelView):
|
|||
class Product(metaclass=PoolMeta):
|
||||
__name__ = 'product.template'
|
||||
farming = fields.Boolean('Farming')
|
||||
cost_type = fields.Selection([
|
||||
('', ''),
|
||||
('materials', 'Materials'),
|
||||
('workforce', 'Workforce'),
|
||||
('indirect', 'Indirect'),
|
||||
], 'Cost Type')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[tryton]
|
||||
version=6.0.32
|
||||
version=6.0.33
|
||||
depends:
|
||||
party
|
||||
company
|
||||
|
@ -10,8 +10,9 @@ depends:
|
|||
sale
|
||||
carrier
|
||||
production
|
||||
account_col
|
||||
analytic_account
|
||||
production_work
|
||||
account_col
|
||||
xml:
|
||||
farming.xml
|
||||
configuration.xml
|
||||
|
|
|
@ -15,10 +15,16 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="planned_date"/>
|
||||
<label name="effective_date"/>
|
||||
<field name="effective_date"/>
|
||||
<label name="uom"/>
|
||||
<field name="uom" widget="selection"/>
|
||||
<label name="workforce_cost"/>
|
||||
<field name="workforce_cost"/>
|
||||
<group col="8" colspan="4" name="compute_costs" >
|
||||
<label name="workforce_cost"/>
|
||||
<field name="workforce_cost"/>
|
||||
<label name="materials_cost"/>
|
||||
<field name="materials_cost"/>
|
||||
<label name="indirect_cost"/>
|
||||
<field name="indirect_cost"/>
|
||||
<label name="total_cost"/>
|
||||
<field name="total_cost"/>
|
||||
</group>
|
||||
</group>
|
||||
<field name="supplies" colspan="4"/>
|
||||
<group col="6" colspan="4" name="state_buttons" >
|
|
@ -6,8 +6,8 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name = "activity"/>
|
||||
<label name = "product"/>
|
||||
<field name = "product"/>
|
||||
<label name= "unit"/>
|
||||
<field name= "unit"/>
|
||||
<label name = "unit_price"/>
|
||||
<field name = "unit_price"/>
|
||||
<label name= "quantity"/>
|
||||
<field name= "quantity"/>
|
||||
<label name= "analytic_account"/>
|
|
@ -3,8 +3,9 @@
|
|||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree editable = "1">
|
||||
<field name = "product" expand="1"/>
|
||||
<field name= "unit" expand="1"/>
|
||||
<field name= "quantity" expand="1"/>
|
||||
<field name= "unit" expand="1"/>
|
||||
<field name= "unit_price" expand="1"/>
|
||||
<field name= "cost_planned" expand="1"/>
|
||||
<field name = "cost_real" expand="1"/>
|
||||
</tree>
|
|
@ -27,22 +27,22 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="production_uom" widget="selection"/>
|
||||
</group>
|
||||
<group id="buttons" col="2" colspan="2">
|
||||
<button name="load_activities" string="Load Activities"
|
||||
icon="tryton-launch"/>
|
||||
<button name="load_stages" string="Load Stage and Activities"
|
||||
icon="tryton-forward"/>
|
||||
<button name="load_lots" string="Load Lots" icon="tryton-launch"/>
|
||||
</group>
|
||||
<label name="quantity_produced"/>
|
||||
<field name="quantity_produced"/>
|
||||
<notebook colspan="4">
|
||||
<page string="Stages" col="4" id="stages">
|
||||
<field name="stages" colspan="4"/>
|
||||
</page>
|
||||
<page string="Lots" col="4" id="lots">
|
||||
<field name="lots" colspan="4"/>
|
||||
</page>
|
||||
<page string="Stages" col="4" id="stages">
|
||||
<field name="stages" colspan="4"/>
|
||||
</page>
|
||||
<page string="Activities" col="2" id="activities">
|
||||
<!-- <page string="Activities" col="2" id="activities">
|
||||
<field name="activities" colspan="4"/>
|
||||
</page>
|
||||
</page> -->
|
||||
<page string="Indicators" col="2" id="indicators">
|
||||
<label name="production_time"/>
|
||||
<field name="production_time"/>
|
||||
|
@ -55,9 +55,9 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<label name="gross_profit"/>
|
||||
<field name="gross_profit"/>
|
||||
</page>
|
||||
<page string="Supplies" col="2" id="supplies">
|
||||
<!-- <page string="Supplies" col="2" id="supplies">
|
||||
<field name="supplies"/>
|
||||
</page>
|
||||
</page> -->
|
||||
<page string="Additional Info" col="2" id="indicators">
|
||||
<label name="company"/>
|
||||
<field name="company" widget="selection"/>
|
||||
|
|
|
@ -4,8 +4,8 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<form>
|
||||
<label name="stage"/>
|
||||
<field name="stage"/>
|
||||
<label name="analytic_account"/>
|
||||
<field name="analytic_account"/>
|
||||
<!-- <label name="analytic_account"/>
|
||||
<field name="analytic_account"/> -->
|
||||
<label name="week"/>
|
||||
<field name="week"/>
|
||||
<label name="effective_date" />
|
||||
|
|
|
@ -6,5 +6,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||
position="after">
|
||||
<label name="farming"/>
|
||||
<field name="farming"/>
|
||||
<label name="cost_type"/>
|
||||
<field name="cost_type"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
|
@ -5,4 +5,5 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="product" expand="1"/>
|
||||
<field name="quantity" expand="1"/>
|
||||
<field name="unit" expand="1"/>
|
||||
<field name="unit_price" expand="1"/>
|
||||
</tree>
|
|
@ -13,6 +13,6 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<label name="standard_cycle"/>
|
||||
<field name="standard_cycle"/>
|
||||
<separator name="notes" colspan="4"/>
|
||||
<field name="activities" colspan="2"/>
|
||||
<field name="cycles" colspan="2"/>
|
||||
<field name="stages" colspan="2"/>
|
||||
<!-- <field name="activities" colspan="2"/> -->
|
||||
</form>
|
||||
|
|
|
@ -14,8 +14,5 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="work_time"/>
|
||||
<label name="uom_time"/>
|
||||
<field name="uom_time" widget="selection"/>
|
||||
<label name="cost_per_hour"/>
|
||||
<field name="cost_per_hour"/>
|
||||
<newline />
|
||||
<field name="supplies" colspan="4"/>
|
||||
</form>
|
|
@ -10,4 +10,5 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="start_time"/>
|
||||
<label name="production_rate"/>
|
||||
<field name="production_rate"/>
|
||||
<field name="activities" colspan="4"/>
|
||||
</form>
|
Loading…
Reference in New Issue