trytonpsk-farming/crop.py

707 lines
25 KiB
Python
Raw Normal View History

2021-11-02 18:25:11 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2022-08-22 23:18:51 +02:00
from dataclasses import field
2021-11-02 18:25:11 +01:00
from decimal import Decimal
2022-08-22 23:18:51 +02:00
from datetime import date, datetime, timedelta
from genericpath import exists
from itertools import product
2022-08-22 23:18:51 +02:00
import copy
2021-11-02 18:25:11 +01:00
from trytond.model import Workflow, ModelView, ModelSQL, fields
from trytond.pyson import Eval, If, Bool, In, Get
2021-11-02 18:25:11 +01:00
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.exceptions import UserError
2022-08-16 06:50:49 +02:00
from trytond.report import Report
from trytond.wizard import (Wizard, StateReport, StateView,
Button, StateTransition)
2021-11-02 18:25:11 +01:00
STATES = {
'readonly': (Eval('state') != 'draft'),
}
2022-08-22 23:18:51 +02:00
MAX_WEEKS = 14
2021-11-02 18:25:11 +01:00
2022-08-19 05:05:25 +02:00
class FarmingStage(ModelSQL, ModelView):
"Farming Stage"
__name__ = "farming.stage"
name = fields.Char('Name', required=True)
class FarmingVarietyCycle(ModelSQL, ModelView):
"Farming Variety Cycle"
__name__ = "farming.variety.cycle"
variety = fields.Many2One('farming.variety', 'Variety', required=True)
2022-08-19 16:59:05 +02:00
sequence = fields.Integer('Sequence', required=True)
2022-08-19 05:05:25 +02:00
stage = fields.Many2One('farming.stage', 'Stage', required=True)
2022-08-19 19:10:12 +02:00
start_time = fields.Integer('Start Time', help='Harvest week',
required=True)
2022-08-19 05:05:25 +02:00
production_rate = fields.Float('Production Rate', digits=(3, 2))
2022-08-16 06:50:49 +02:00
class FarmingVariety(ModelSQL, ModelView):
'Farming Variety'
__name__ = 'farming.variety'
product = fields.Many2One('product.product', 'Product', required=True)
2022-08-22 23:18:51 +02:00
production_rate = fields.Float('Production Rate', digits=(16, 2))
production_uom = fields.Many2One('product.uom', 'Uom')
2022-08-19 05:05:25 +02:00
standard_cycle = fields.Integer('Standard Cycle', help='In weeks')
2022-08-16 06:50:49 +02:00
activities = fields.One2Many('farming.variety.activity', 'variety',
'Activities')
2022-08-19 05:05:25 +02:00
cycles = fields.One2Many('farming.variety.cycle', 'variety', 'Cycles')
2022-08-16 06:50:49 +02:00
def get_rec_name(self, name=None):
return self.product.template.name
class FarmingActivitySupply(ModelSQL, ModelView):
'Farming Activity Supply'
__name__ = 'farming.variety.activity.supply'
activity = fields.Many2One('farming.variety.activity', 'Activity')
product = fields.Many2One("product.product", "Product", required=True,
select=True)
unity = fields.Function(fields.Char('Unity'), 'get_unity')
quantity = fields.Float('Quantity', required=True)
def get_unity(self, name=None):
unity = self.product.default_uom.name
return unity
2022-08-16 06:50:49 +02:00
class FarmingVarietyActivity(ModelSQL, ModelView):
'Farming Variety Activity'
__name__ = 'farming.variety.activity'
variety = fields.Many2One('farming.variety', 'Variety', required=True)
sequence = fields.Integer('Sequence', required=True )
2022-08-16 06:50:49 +02:00
kind = fields.Many2One('farming.activity.kind', 'Kind', required=True)
work_time = fields.Numeric('Work Time')
uom = fields.Many2One('product.uom', 'Unity')
supplies = fields.One2Many('farming.variety.activity.supply', 'activity', 'Supply')
2022-08-16 06:50:49 +02:00
time_of_realization = fields.Integer('Time Of Realization', required=True,
help='In weeks')
2022-08-19 16:59:05 +02:00
class CropStage(ModelSQL, ModelView):
"Crop Stage"
__name__ = "farming.crop.stage"
crop = fields.Many2One('farming.crop', 'Crop', required=True)
stage = fields.Many2One('farming.stage', 'Stage', required=True)
activity_time = fields.Float('Act. Time', required=True)
2022-08-22 23:18:51 +02:00
production_rate = fields.Float('Production Rate', digits=(3, 2))
2022-08-19 16:59:05 +02:00
2021-11-02 18:25:11 +01:00
class Kind(ModelSQL, ModelView):
"Kind"
__name__ = "farming.activity.kind"
name = fields.Char('Name', required=True)
activity_time = fields.Float('Act. Time', required=True)
2022-08-16 06:50:49 +02:00
class FarmingCrop(Workflow, ModelSQL, ModelView):
'Farming Crop'
__name__ = 'farming.crop'
2021-11-02 18:25:11 +01:00
_rec_name = 'number'
number = fields.Char('Number', readonly=True)
2022-08-16 06:50:49 +02:00
variety = fields.Many2One('farming.variety', 'Variety', required=True,
2021-11-02 18:25:11 +01:00
states=STATES)
location = fields.Many2One('farming.location', 'Location', required=True,
states=STATES)
company = fields.Many2One('company.company', 'Company', required=True,
states=STATES, domain=[('id', If(In('company',
Eval('context', {})), '=', '!='), Get(Eval('context', {}),
'company', 0)), ])
start_date = fields.Date('Start Date', states=STATES, depends=['state'])
end_date = fields.Date('End Date', states=STATES, depends=['state'])
field_size = fields.Float('Field Size', states=STATES, select=True, help='In hectares')
2022-08-19 05:05:25 +02:00
quantity_produced_planned = fields.Function(fields.Float('Quantity Produced'),
'get_quantity_produced_planned')
2021-11-02 18:25:11 +01:00
quantity_produced = fields.Float('Quantity Produced', states=STATES)
2022-08-22 23:18:51 +02:00
production_uom = fields.Many2One('product.uom', 'Production UoM', states=STATES)
2022-08-19 16:59:05 +02:00
lots = fields.One2Many('farming.crop.lot', 'crop', 'Lots', states=STATES)
stages = fields.One2Many('farming.crop.stage', 'crop', 'Stages',
states=STATES)
2022-09-02 22:35:49 +02:00
#activities = fields.One2Many('farming.crop.activities', 'crop', 'Activities', states=STATES)
2022-08-19 05:05:25 +02:00
# seed = fields.Char('Seed', states=STATES)
seed = fields.Many2One('farming.seed', 'Seed', required=True)
2022-08-22 23:18:51 +02:00
production_rate = fields.Float('Production Rate')
2021-11-02 18:25:11 +01:00
notes = fields.Text('Notes', states=STATES)
state = fields.Selection([
('draft', 'Draft'),
('production', 'Production'),
('finished', 'Finished'),
('cancelled', 'Cancelled'),
], 'State', readonly=True, required=True)
# Financial indicators
production_time = fields.Function(fields.Integer('Production Time'),
'get_production_time')
production_cost = fields.Function(fields.Numeric('Production Cost'),
'get_production_cost')
performance = fields.Function(fields.Numeric('Performance'),
'get_performance')
gross_profit_rate = fields.Function(fields.Float('Gross Profit Rate'),
'get_gross_profit_rate')
gross_profit = fields.Function(fields.Numeric('Gross Profit'),
'get_gross_profit')
@classmethod
def __setup__(cls):
2022-08-16 06:50:49 +02:00
super(FarmingCrop, cls).__setup__()
2021-11-02 18:25:11 +01:00
cls._order.insert(0, ('create_date', 'DESC'))
cls._order.insert(1, ('id', 'DESC'))
cls._transitions |= set((
('draft', 'production'),
('production', 'draft'),
('production', 'finished'),
('production', 'cancelled'),
))
cls._buttons.update({
'draft': {
'invisible': Eval('state').in_(['draft', 'finished'])
},
'cancel': {
'invisible': Eval('state') == 'finished',
},
'load_configuration': {
'invisible': (Eval('lines', [])
| (Eval('state') != 'draft')),
'depends': ['state'],
},
2021-11-02 18:25:11 +01:00
'production': {
'invisible': Eval('state').in_(['cancelled', 'finished']),
},
'finished': {
'invisible': Eval('state') != 'production',
},
})
@staticmethod
def default_start_date():
return date.today()
2021-11-02 18:25:11 +01:00
@staticmethod
def default_company():
return Transaction().context.get('company') or False
@staticmethod
def default_state():
return 'draft'
@classmethod
@ModelView.button
@Workflow.transition('finished')
def finished(cls, records):
pass
@classmethod
@ModelView.button
@Workflow.transition('cancelled')
def cancel(cls, services):
pass
@classmethod
@ModelView.button
@Workflow.transition('draft')
def draft(cls, records):
pass
@classmethod
@ModelView.button
@Workflow.transition('production')
def production(cls, records):
for record in records:
record.set_number()
@classmethod
def clear_bed_lines(cls, crops):
Line = Pool().get('farming.crop.lot.bed')
lines_to_delete = []
for crop in crops:
for lot in crop.lots:
for bed in lot.beds:
lines_to_delete.append(bed)
Line.delete(lines_to_delete)
@classmethod
def create_beds_lines(cls, crops):
Line = Pool().get('farming.crop.lot.bed')
lines = []
for crop in crops:
for lot in crop.lots:
for bed in lot.lot.beds:
line = Line(
lot = lot.id,
bed = bed.id,
quantity_plants = bed.quantity,
unit = 20,
production_rate = 10,
)
lines.append(line)
Line.save(lines)
@classmethod
def create_lots_lines(cls, crops):
Line = Pool().get('farming.crop.lot')
lines = []
cls.clear_bed_lines(crops)
cls.clear_lots_lines(crops)
for crop in crops:
for lot in crop.location.lots:
line = Line(
crop = crop.id,
lot = lot.id,
cycle = 0,
beds = [],
activities = [],
total_plants = lot.quantity
)
lines.append(line)
Line.save(lines)
cls.create_beds_lines(crops)
@classmethod
def clear_lots_lines(cls, crops):
Line = Pool().get('farming.crop.lot')
lines_to_delete = []
for crop in crops:
for lot in crop.lots:
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:
line = Line(
crop = crop.id,
stage = stage.stage.id,
activity_time = stage.start_time,
production_rate = stage.production_rate,
)
lines.append(line)
Line.save(lines)
@classmethod
def create_activities_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:
line = Line(
crop = crop.id,
stage = stage.stage.id,
activity_time = stage.start_time,
production_rate = stage.production_rate,
)
lines.append(line)
Line.save(lines)
@classmethod
def clear_stages_lines(cls, crops):
Line = Pool().get('farming.crop.stage')
lines_to_delete = []
for crop in crops:
for stage in crop.stages:
lines_to_delete.append(stage)
print(stage.stage)
Line.delete(lines_to_delete)
@classmethod
@ModelView.button
def load_configuration(cls, crops):
cls.clear_stages_lines(crops)
cls.clear_bed_lines(crops)
cls.clear_lots_lines(crops)
cls.create_stages_lines(crops)
cls.create_lots_lines(crops)
cls.create_beds_lines(crops)
2021-11-02 18:25:11 +01:00
def set_number(self):
Config = Pool().get('farming.configuration')
config = Config.get_config()
if not config.farming_production_sequence:
raise UserError('missing_sequence_farming_production')
number = config.farming_production_sequence.get()
self.write([self], {'number': number})
2022-08-19 05:05:25 +02:00
def get_quantity_produced_planned(self, name=None):
res = []
_append = res.append
for lot in self.lots:
2022-08-22 23:18:51 +02:00
if self.production_rate and lot.total_plants:
_append(self.production_rate * lot.total_plants)
2022-08-19 05:05:25 +02:00
return sum(res)
def get_production_time(self, name=None):
2021-11-02 18:25:11 +01:00
res = None
if self.start_date:
today = date.today()
if self.end_date:
res = (self.end_date - self.start_date).days
else:
res = (today - self.start_date).days
return res
def get_production_cost(self, name):
res = 0
return res
def get_performance(self, name):
res = 0
return res
def get_gross_profit_rate(self, name):
res = 0
return res
def get_gross_profit(self, name):
res = 0
return res
2022-08-22 23:18:51 +02:00
@fields.depends('variety', 'production_uom', 'production_rate')
def on_change_variety(self):
if self.variety and self.variety.production_uom:
self.production_uom = self.variety.production_uom.id
self.production_rate = self.variety.production_rate
if self.variety.standard_cycle:
self.end_date = date.today() + timedelta(weeks=self.variety.standard_cycle)
2021-11-02 18:25:11 +01:00
2022-08-16 06:50:49 +02:00
class FarmingCropLot(ModelSQL, ModelView):
'Farming Crop Lot'
__name__ = 'farming.crop.lot'
2022-08-22 23:18:51 +02:00
_rec_name = 'number'
crop = fields.Many2One('farming.crop', 'Crop', ondelete='CASCADE', required=True)
2022-08-22 23:18:51 +02:00
lot = fields.Many2One('farming.location.lot', 'Lot', required=True)
2022-08-16 06:50:49 +02:00
cycle = fields.Float('Cycle', digits=(16, 2), help="In weeks")
2022-08-22 23:18:51 +02:00
#production_rate = fields.Float('Production Rate')
2022-08-16 06:50:49 +02:00
beds = fields.One2Many('farming.crop.lot.bed', 'lot', 'Beds')
activities = fields.One2Many('farming.activity', 'lot', 'Activities')
total_plants = fields.Integer('Total Plants', states = {'readonly': Bool(Eval('beds'))}, depends=['beds'])
@fields.depends('beds')
def on_change_with_total_plants(self, name = None):
quantity = 0
if self.beds:
for bed in self.beds:
if bed.quantity_plants:
quantity += bed.quantity_plants
return quantity
2022-08-16 06:50:49 +02:00
class FarmingCropLotBed(ModelSQL, ModelView):
'Crop Lot Bed'
__name__ = 'farming.crop.lot.bed'
_rec_name = 'code'
lot = fields.Many2One('farming.crop.lot', 'Lot', ondelete='CASCADE', required=True)
bed = fields.Many2One('farming.location.lot.bed', 'Bed', ondelete='CASCADE', required=True)
quantity_plants = fields.Integer('Quantity Plants')
unit = fields.Many2One('product.uom', 'Unit', ondelete='CASCADE')
2022-07-15 09:01:45 +02:00
production_rate = fields.Float('Production Rate', digits=(16, 2),
2022-08-16 06:50:49 +02:00
help="In the unit of measure")
#class CropActivity(Workflow, ModelSQL, ModelView):
# 'Crop Activity'
# __name__ = 'crop.activity'
# sequence = fields.Char('Sequence', states=STATES)
# start_date = fields.Date('Start Date', states=STATES, required=True)
# work_time = fields.Numeric('Work Time', digits=(16, 2))
# supplies = fields.One2Many('crop.activity.supply', 'activity', 'Supply')
# #notes = fields.Text('Notes', states=STATES)
# # works = fields.One2Many('farming.crop.work', 'activity', 'Works',
# # states=STATES)
# #state = fields.Selection([
# # ('draft', 'Draft'),
# # ('execution', 'Execution'),
# # ('done', 'Done'),
# # ('cancelled', 'Cancelled'),
# # ], 'State', readonly=True, required=True)
# #amount = fields.Function(fields.Numeric('Amount', digits=(16, 2)),
# # 'get_amount')
#
#
#class CropActivitySupply(ModelSQL, ModelView):
# 'Crop Activity Supply'
# __name__ = 'crop.activity.supply'
# activity = fields.Many2One('crop.activity', 'Activity')
# product = fields.Many2One("product.product", "Product", required=True,
# select=True)
# unity = fields.Function(fields.Char('Unity'), 'get_unity')
# quantity = fields.Float('Quantity', required=True)
# 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
2021-11-02 18:25:11 +01:00
class Activity(Workflow, ModelSQL, ModelView):
'Activity'
__name__ = 'farming.activity'
_rec_name = 'kind'
sequence = fields.Char('Sequence', states=STATES)
2022-08-16 06:50:49 +02:00
lot = fields.Many2One('farming.crop.lot', 'Lot', required=True,
states=STATES)
employee = fields.Many2One('party.party', 'Employee', states=STATES)
2021-11-02 18:25:11 +01:00
planned_date = fields.Date('Planned Date', states=STATES, required=True)
start_date = fields.Date('Start Date', states=STATES, required=True)
end_date = fields.Date('End Date', states=STATES)
kind = fields.Many2One('farming.activity.kind', 'Kind', states=STATES)
notes = fields.Text('Notes', states=STATES)
days = fields.Function(fields.Integer('Days', states=STATES), 'get_days')
shipments = fields.Many2Many('farming.activity-shipment.internal',
'activity', 'shipment', 'Shipments', states=STATES)
2022-08-16 06:50:49 +02:00
# works = fields.One2Many('farming.crop.work', 'activity', 'Works',
# states=STATES)
2021-11-02 18:25:11 +01:00
state = fields.Selection([
('draft', 'Draft'),
('execution', 'Execution'),
('done', 'Done'),
('cancelled', 'Cancelled'),
], 'State', readonly=True, required=True)
2022-08-16 06:50:49 +02:00
amount = fields.Function(fields.Numeric('Amount', digits=(16, 2)),
'get_amount')
2021-11-02 18:25:11 +01:00
@classmethod
def __setup__(cls):
super(Activity, cls).__setup__()
cls._order.insert(0, ('planned_date', 'DESC'))
cls._order.insert(1, ('id', 'DESC'))
cls._transitions |= set((
('draft', 'execution'),
('execution', 'done'),
('execution', 'draft'),
('execution', 'cancelled'),
('cancelled', 'draft'),
))
cls._buttons.update({
'draft': {
'invisible': Eval('state').in_(['draft', 'done']),
},
'cancel': {
'invisible': Eval('state').in_(['cancelled', 'done']),
},
'execution': {
'invisible': Eval('state') != 'draft',
},
'done': {
'invisible': Eval('state') != 'execution',
},
})
@staticmethod
def default_company():
return Transaction().context.get('company') or False
@staticmethod
def default_state():
return 'draft'
@classmethod
@ModelView.button
@Workflow.transition('done')
def done(cls, records):
pass
@classmethod
@ModelView.button
@Workflow.transition('execution')
def execution(cls, records):
for record in records:
record.set_number()
@classmethod
@ModelView.button
@Workflow.transition('cancelled')
def cancel(cls, records):
pass
@classmethod
@ModelView.button
@Workflow.transition('draft')
def draft(cls, records):
pass
def get_amount(self, name):
res = 0
for shipment in self.shipments:
for m in shipment.outgoing_moves:
res += m.product.template.cost_price * Decimal(m.quantity)
for w in self.works:
res += w.unit_price * Decimal(w.quantity)
return res
def get_days(self, name):
res = 0
if self.start_date and self.end_date:
res = (self.end_date - self.start_date).days
return res
2022-08-16 06:50:49 +02:00
class CropForecastStart(ModelView):
'Crop Forecast Start'
__name__ = 'farming.crop_forecast.start'
company = fields.Many2One('company.company', 'Company', required=True)
2022-08-17 00:46:41 +02:00
start_date = fields.Date("Start Date", required=True)
2022-08-22 23:18:51 +02:00
end_date = fields.Date("End Date", required=True)
2022-08-16 06:50:49 +02:00
# storage = fields.Many2One('stock.location', 'Location', required=True,
# domain=[('type', '=', 'storage')])
2021-11-02 18:25:11 +01:00
2022-08-16 06:50:49 +02:00
@staticmethod
def default_company():
return Transaction().context.get('company')
2021-11-02 18:25:11 +01:00
2022-08-16 06:50:49 +02:00
class CropForecast(Wizard):
'Crop Forecast'
__name__ = 'farming.crop_forecast'
start = StateView('farming.crop_forecast.start',
'farming.farming_crop_forecast_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Print', 'print_', 'tryton-ok', default=True),
])
print_ = StateReport('farming.crop_forecast.report')
def do_print_(self, action):
data = {
'company': self.start.company.id,
2022-08-17 00:46:41 +02:00
'start_date': self.start.start_date,
2022-08-16 06:50:49 +02:00
}
return action, data
def transition_print_(self):
return 'end'
class CropForecastReport(Report):
'Crop Forecast Report'
__name__ = 'farming.crop_forecast.report'
2022-08-22 23:18:51 +02:00
2022-08-16 06:50:49 +02:00
@classmethod
def get_context(cls, records, header, data):
report_context = super().get_context(records, header, data)
pool = Pool()
Company = pool.get('company.company')
2022-08-17 00:46:41 +02:00
Crop = pool.get('farming.crop')
2022-08-22 23:18:51 +02:00
stages = {}
stages_convert = {}
week_range = []
for nd in range(MAX_WEEKS):
week_n = 'day' + str((nd + 1))
first_date = data['start_date'] + timedelta(nd * 7)
last_date = first_date + timedelta(7)
data[week_n] = first_date
data['total_' + week_n] = 0
2022-08-17 00:46:41 +02:00
# data[('revenue_' + day_n)] = 0
# data[('rate_' + day_n)] = 0
2022-08-22 23:18:51 +02:00
stages[week_n] = ''
stages[first_date] = week_n
week_range.append((first_date, last_date))
#stages_convert[tdate] = day_n
2022-08-17 00:46:41 +02:00
target_crops = data['start_date'] - timedelta(days=300)
crops = Crop.search([
2022-08-22 23:18:51 +02:00
('start_date', '>=', target_crops),
2022-08-17 00:46:41 +02:00
])
2022-08-16 06:50:49 +02:00
2022-08-22 23:18:51 +02:00
records = {}
for crop in crops:
stages_cycle = copy.deepcopy(stages)
production_rate = crop.variety.production_rate
2022-08-22 23:18:51 +02:00
records[crop] = []
quantity_produced = crop.quantity_produced
start_date = crop.start_date
print(crop)
for stage in crop.stages:
#production_rate = stage.production_rate
2022-08-22 23:18:51 +02:00
if production_rate:
production_date = start_date + timedelta(days=stage.activity_time * 7)
production = (production_rate / 100) * quantity_produced
for (start_week, end_week) in week_range:
print(start_week, production_date, end_week)
if production_date >= start_week and production_date <= end_week:
week_n = stages[start_week]
stages_cycle[week_n] = production
print(start_week, production)
break
for lot in crop.lots:
record = {
'number': lot.lot.number,
}
record.update(stages_cycle)
records[crop].append(record)
print('stage_cycle: ', record)
#for line in lines:
# _delta = (line.departure_date - line.arrival_date).days
# for i in range(_delta):
# dt = line.arrival_date + timedelta(i)
# if dt >= date_init and dt < date_limit \
# and dt >= data['date']:
# dayn = alldays_convert[dt]
# records[line.crop.id][dayn] = "X"
# data['total_' + dayn] += 1
# data['revenue_' + dayn] += float(line.unit_price) / 1000000
#for i in range(MAX_DAYS):
# day_n = 'day' + str((i + 1))
# data['rate_' + day_n] = (data['total_' + day_n] * 100.0) / len(crops)
report_context['records'] = records.items()
report_context['start_date'] = start_date
#data['date']
2022-08-17 00:46:41 +02:00
report_context['company'] = Company(data['company']).party.name
2022-08-16 06:50:49 +02:00
return report_context
2022-08-22 23:18:51 +02:00
2022-08-16 06:50:49 +02:00
# class FarmingWork(ModelSQL, ModelView):
# 'Farming Work'
# __name__ = 'farming.crop.work'
# sequence = fields.Integer('Sequence', select=True)
# activity = fields.Many2One('farming.activity', 'Activity', select=True,
# ondelete='CASCADE', required=True)
# method = fields.Selection([
# ('by_day', 'By Day'),
# ('by_productivity', 'By Productivity'),
# ], 'Method', required=True)
# quantity = fields.Float('Quantity', required=True)
# unit_price = fields.Numeric('Unit Price', digits=(16, 2), required=True)
# amount = fields.Function(fields.Numeric('Amount', digits=(16, 2)), 'get_amount')
# employee = fields.Many2One('company.employee', 'Employee')
#
# @classmethod
# def __setup__(cls):
# super(FarmingWork, cls).__setup__()
#
# def get_amount(self, name):
# res = 0
# if self.quantity and self.unit_price:
# res = Decimal(self.quantity) * self.unit_price
# return res
#
# @staticmethod
# def default_method():
# return 'by_day'
2021-11-02 18:25:11 +01:00
class FarmingActivityShipmentInternal(ModelSQL):
'Farming Activity - Shipment Internal'
__name__ = 'farming.activity-shipment.internal'
_table = 'farming_activity_shipment_internal_rel'
activity = fields.Many2One('farming.activity', 'Activity',
ondelete='CASCADE', select=True, required=True)
shipment = fields.Many2One('stock.shipment.internal', 'Tax',
ondelete='RESTRICT', required=True)