This commit is contained in:
oscar alvarez 2023-01-17 15:11:54 -05:00
parent e6c7fc5c8a
commit 0440e7a12a
10 changed files with 150 additions and 25 deletions

View File

@ -42,6 +42,7 @@ def register():
crop.CropActivitiesStart,
crop.CropSuppliesStart,
crop.SupplyMoves,
crop.CropStageLoss,
location.FarmingLocationLotBed,
location.FarmingLocationLot,
location.FarmingLocation,

94
crop.py
View File

@ -112,9 +112,10 @@ class VarietyStageActivitySupply(ModelSQL, ModelView):
return None
class CropStage(ModelSQL, ModelView):
class CropStage(Workflow, ModelSQL, ModelView):
"Crop Stage"
__name__ = "farming.crop.stage"
sequence = fields.Integer('Sequence', required=True)
crop = fields.Many2One('farming.crop', 'Crop', required=True)
stage = fields.Many2One('farming.stage', 'Stage', required=True)
week = fields.Float('Week', required=True)
@ -125,8 +126,65 @@ class CropStage(ModelSQL, ModelView):
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')
total_cost = fields.Function(fields.Numeric(
'Total Cost', digits=(16, 2)), 'get_total_cost')
losses = fields.One2Many('farming.crop.stage.loss', 'stage', 'Losses')
total_losses = fields.Function(fields.Numeric(
'Total Losses', digits=(16, 2)), 'get_total_losses')
state = fields.Selection([
('pending', 'Pending'),
('running', 'Running'),
('finished', 'Finished'),
('cancelled', 'Cancelled'),
], 'State', readonly=True, required=True)
@classmethod
def __setup__(cls):
super(CropStage, cls).__setup__()
cls._order.insert(0, ('sequence', 'ASC'))
cls._transitions |= set((
('pending', 'running'),
('running', 'finished'),
('running', 'pending'),
))
cls._buttons.update({
'pending': {
'invisible': Eval('state').in_(['pending', 'finished'])
},
'running': {
'invisible': Eval('state').in_(['finished', 'running']),
},
'finished': {
'invisible': Eval('state') != 'running',
}})
@classmethod
@ModelView.button
@Workflow.transition('pending')
def pending(cls, records):
pass
@classmethod
@ModelView.button
@Workflow.transition('running')
def running(cls, records):
pass
@classmethod
@ModelView.button
@Workflow.transition('finished')
def finished(cls, records):
pass
@staticmethod
def default_state():
return 'pending'
def get_total_losses(self, name=None):
return sum(lo.quantity for lo in self.losses)
def get_total_cost(self, name=None):
return sum(act.total_cost or 0 for act in self.activities)
def get_quantity_planned(self, name=None):
res = 0
@ -135,6 +193,15 @@ class CropStage(ModelSQL, ModelView):
return round(res, 2)
class CropStageLoss(Workflow, ModelSQL, ModelView):
'Crop Stage Loss'
__name__ = 'farming.crop.stage.loss'
stage = fields.Many2One('farming.crop.stage', 'Stage', ondelete='CASCADE')
date = fields.Date('Date', required=True)
quantity = fields.Integer('Quantity', required=True)
reason = fields.Text('Reason', required=True)
class Kind(ModelSQL, ModelView):
"Activity Kind"
__name__ = "farming.activity.kind"
@ -164,6 +231,8 @@ class Crop(Workflow, ModelSQL, ModelView):
total_plants = fields.Integer('Total Plants')
quantity_planned = fields.Function(fields.Float('Quantity Planned'),
'get_quantity_planned')
quantity_planned_net = fields.Function(fields.Float('Net. Quantity Planned'),
'get_quantity_planned_net')
quantity_produced = fields.Float('Quantity Produced', states=STATES)
production_uom = fields.Many2One('product.uom', 'Production UoM', states=STATES)
lots = fields.One2Many('farming.crop.lot', 'crop', 'Lots', states=STATES)
@ -187,7 +256,7 @@ class Crop(Workflow, ModelSQL, ModelView):
'get_production_time')
production_cost = fields.Function(fields.Numeric('Production Cost'),
'get_production_cost')
performance = fields.Function(fields.Numeric('Performance'),
performance = fields.Function(fields.Float('Performance', digits=(4, 2)),
'get_performance')
gross_profit_rate = fields.Function(fields.Float('Gross Profit Rate'),
'get_gross_profit_rate')
@ -195,6 +264,10 @@ class Crop(Workflow, ModelSQL, ModelView):
'get_gross_profit')
# Deprecation warning: activities was moved to farming.crop.stage
# activities = fields.One2Many('farming.crop.activity', 'crop', 'Activities')
total_cost = fields.Function(fields.Numeric(
'Total Cost', digits=(16, 2)), 'get_total_cost')
total_losses = fields.Function(fields.Numeric(
'Total Losses', digits=(16, 2)), 'get_total_losses')
@classmethod
def __setup__(cls):
@ -267,6 +340,12 @@ class Crop(Workflow, ModelSQL, ModelView):
for record in records:
record.set_number()
def get_total_cost(self, name=None):
return sum(act.total_cost or 0 for act in self.stages)
def get_total_losses(self, name=None):
return sum(st.total_losses for st in self.stages)
@classmethod
def clear_bed_lines(cls, crops):
Line = Pool().get('farming.crop.lot.bed')
@ -382,6 +461,7 @@ class Crop(Workflow, ModelSQL, ModelView):
for stage in self.variety.stages:
effec_date = self.start_date + timedelta(weeks=stage.start_time)
_stage = CropStage(
sequence=stage.sequence,
crop=self.id,
stage=stage.stage.id,
production_rate=stage.production_rate,
@ -529,6 +609,10 @@ class Crop(Workflow, ModelSQL, ModelView):
number = config.farming_production_sequence.get()
self.write([self], {'number': number})
def get_quantity_planned_net(self, name=None):
return self.quantity_planned - (
self.total_losses * self.production_rate)
def get_quantity_planned(self, name=None):
res = []
_append = res.append
@ -552,7 +636,7 @@ class Crop(Workflow, ModelSQL, ModelView):
return res
def get_performance(self, name):
res = 0
res = (self.quantity_produced / self.quantity_planned_net) * 100
return res
def get_gross_profit_rate(self, name):

View File

@ -6,12 +6,12 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.ui.view" id="farming_crop_stage_view_tree">
<field name="model">farming.crop.stage</field>
<field name="type">tree</field>
<field name="name">farming_crop_stage_tree</field>
<field name="name">crop_stage_tree</field>
</record>
<record model="ir.ui.view" id="farming_crop_stage_view_form">
<field name="model">farming.crop.stage</field>
<field name="type">form</field>
<field name="name">farming_crop_stage_form</field>
<field name="name">crop_stage_form</field>
</record>
<record model="ir.ui.view" id="farming_stage_view_tree">
@ -111,12 +111,12 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.ui.view" id="farming_crop_view_form">
<field name="model">farming.crop</field>
<field name="type">form</field>
<field name="name">farming_crop_form</field>
<field name="name">crop_form</field>
</record>
<record model="ir.ui.view" id="farming_crop_view_tree">
<field name="model">farming.crop</field>
<field name="type">tree</field>
<field name="name">farming_crop_tree</field>
<field name="name">crop_tree</field>
</record>
<record model="ir.action.act_window" id="act_farming_crop_form">
<field name="name">Crop</field>
@ -324,8 +324,19 @@ this repository contains the full copyright notices and license terms. -->
<field name="action" ref="report_farming_crop"/>
</record>
<!--
<record model="ir.ui.view" id="farming_crop_stage_loss_view_tree">
<field name="model">farming.crop.stage.loss</field>
<field name="type">tree</field>
<field name="name">crop_stage_loss_tree</field>
</record>
<record model="ir.ui.view" id="farming_crop_stage_loss_view_form">
<field name="model">farming.crop.stage.loss</field>
<field name="type">form</field>
<field name="name">crop_stage_loss_form</field>
</record>
<!--
<record model="ir.model.button" id="production_farming_cancel_button">
<field name="name">cancel</field>
<field name="model" search="[('model', '=', 'farming.production')]"/>

View File

@ -1,5 +1,5 @@
[tryton]
version=6.0.33
version=6.0.34
depends:
party
company

View File

@ -14,11 +14,11 @@ this repository contains the full copyright notices and license terms. -->
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
<label name="analytic_account"/>
<field name="analytic_account" widget="selection"/>
<group id="quantities" col="8" colspan="4">
<group id="quantities" col="10" colspan="4">
<label name="total_plants"/>
<field name="total_plants"/>
<label name="total_losses"/>
<field name="total_losses"/>
<label name="production_rate"/>
<field name="production_rate"/>
<label name="quantity_planned"/>
@ -31,6 +31,8 @@ this repository contains the full copyright notices and license terms. -->
icon="tryton-forward"/>
<button name="load_lots" string="Load Lots" icon="tryton-launch"/>
</group>
<label name="quantity_planned_net"/>
<field name="quantity_planned_net"/>
<label name="quantity_produced"/>
<field name="quantity_produced"/>
<notebook colspan="4">
@ -65,18 +67,16 @@ this repository contains the full copyright notices and license terms. -->
<field name="field_size"/>
</page>
</notebook>
<group col="6" colspan="4" id="state_buttons">
<group col="8" colspan="4" id="state_buttons">
<label name="total_cost"/>
<field name="total_cost"/>
<label name="state"/>
<field name="state"/>
<group col="4" colspan="2" id="buttons">
<button name="draft" string="Draft"
icon="tryton-clear"/>
<button name="production" string="Production"
icon="tryton-forward"/>
<button name="cancel" string="Cancel"
icon="tryton-cancel"/>
<button name="finished" string="Finished"
icon="tryton-ok"/>
<button name="draft" string="Draft" icon="tryton-clear"/>
<button name="production" string="Production" icon="tryton-forward"/>
<button name="cancel" string="Cancel" icon="tryton-cancel"/>
<button name="finished" string="Finished" icon="tryton-ok"/>
</group>
</group>
</form>

View File

@ -4,15 +4,24 @@ 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="week"/>
<field name="week"/>
<label name="effective_date" />
<field name="effective_date" />
<label name="production_rate"/>
<field name="production_rate"/>
<label name="quantity_planned"/>
<field name="quantity_planned"/>
<label name="quantity_produced"/>
<field name="quantity_produced"/>
<label name="total_cost"/>
<field name="total_cost"/>
<label name="total_losses"/>
<field name="total_losses"/>
<label name="state"/>
<field name="state"/>
<field name="activities" colspan="4"/>
<field name="losses" colspan="4"/>
<label name="state"/>
<field name="state"/>
</form>

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<form>
<label name="date"/>
<field name="date"/>
<label name="quantity"/>
<field name="quantity"/>
<label name="reason" />
<field name="reason" />
</form>

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<tree>
<field name="date"/>
<field name="quantity"/>
<field name="reason" />
</tree>

View File

@ -1,9 +1,12 @@
<?xml version="1.0"?>
<tree>
<field name="sequence" expand="1"/>
<field name="stage" expand="1"/>
<field name="week" expand="1"/>
<field name="production_rate" expand="1"/>
<field name="quantity_planned" expand="1"/>
<field name="effective_date" expand="1"/>
<field name="total_losses"/>
<field name="quantity_produced" expand="1"/>
<field name="state" expand="1"/>
</tree>