This commit is contained in:
Oscar 2021-11-02 12:25:11 -05:00
parent 9c41c74ad3
commit 83be1c4f94
11 changed files with 792 additions and 601 deletions

View File

@ -2,22 +2,23 @@
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool
from . import configuration
from . import production
from . import farm_production
from . import location
from . import quality
from . import purchase
from . import sale
from . import product
from . import production
def register():
Pool.register(
configuration.Configuration,
production.Kind,
production.Activity,
production.FarmingWork,
production.FarmingProduction,
production.FarmingActivityShipmentInternal,
farm_production.Kind,
farm_production.Activity,
farm_production.FarmingWork,
farm_production.FarmingProduction,
farm_production.FarmingActivityShipmentInternal,
location.FarmingLocation,
quality.QualityTest,
quality.QualityAnalysis,
@ -34,6 +35,7 @@ def register():
sale.SaleLineKit,
sale.SaleLineKitComponent,
product.Product,
production.Production,
module='farming', type_='model')
Pool.register(
purchase.PurchaseFarming,

304
farm_production.py Normal file
View File

@ -0,0 +1,304 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from __future__ import with_statement
from decimal import Decimal
from datetime import date
from trytond.model import Workflow, ModelView, ModelSQL, fields
from trytond.pyson import Eval, If, In, Get
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.exceptions import UserError
STATES = {
'readonly': (Eval('state') != 'draft'),
}
class Kind(ModelSQL, ModelView):
"Kind"
__name__ = "farming.activity.kind"
name = fields.Char('Name', required=True)
activity_time = fields.Float('Act. Time', required=True)
@classmethod
def __setup__(cls):
super(Kind, cls).__setup__()
cls._order.insert(0, ('name', 'ASC'))
class FarmingProduction(Workflow, ModelSQL, ModelView):
'Farming Production'
__name__ = 'farming.production'
_rec_name = 'number'
number = fields.Char('Number', readonly=True)
product = fields.Many2One('product.product', 'Product', required=True,
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')
quantity_produced = fields.Float('Quantity Produced', states=STATES)
quantity_produced_uom = fields.Many2One('product.uom', 'Quantity UoM', states=STATES)
activities = fields.One2Many('farming.activity', 'production', 'Activities', states=STATES)
lot = fields.Char('Lot', states=STATES)
seed = fields.Char('Seed', required=True, states=STATES)
description = fields.Char('Description', states=STATES)
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):
super(FarmingProduction, cls).__setup__()
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',
},
'production': {
'invisible': Eval('state').in_(['cancelled', 'finished']),
},
'finished': {
'invisible': Eval('state') != 'production',
},
})
@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()
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})
def get_production_time(self, name):
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
class Activity(Workflow, ModelSQL, ModelView):
'Activity'
__name__ = 'farming.activity'
_rec_name = 'kind'
sequence = fields.Char('Sequence', states=STATES)
production = fields.Many2One('farming.production', 'Production', states=STATES)
employee = fields.Many2One('party.party', 'Employee', states=STATES, select=True)
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)
works = fields.One2Many('farming.production.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')
@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
class FarmingWork(ModelSQL, ModelView):
'Farming Work'
__name__ = 'farming.production.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'
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)

235
farm_production.xml Normal file
View File

@ -0,0 +1,235 @@
<?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. -->
<tryton>
<data>
<record model="ir.ui.view" id="farming_work_view_tree">
<field name="model">farming.production.work</field>
<field name="type">tree</field>
<field name="name">farming_work_tree</field>
</record>
<record model="ir.ui.view" id="farming_work_view_form">
<field name="model">farming.production.work</field>
<field name="type">form</field>
<field name="name">farming_work_form</field>
</record>
<record model="ir.ui.view" id="farming_activity_kind_view_tree">
<field name="model">farming.activity.kind</field>
<field name="type">tree</field>
<field name="name">farming_activity_kind_tree</field>
</record>
<record model="ir.ui.view" id="farming_activity_kind_view_form">
<field name="model">farming.activity.kind</field>
<field name="type">form</field>
<field name="name">farming_activity_kind_form</field>
</record>
<record model="ir.action.act_window" id="act_farming_activity_kind_tree">
<field name="name">Activity Kind</field>
<field name="res_model">farming.activity.kind</field>
</record>
<record model="ir.action.act_window.view" id="act_farming_activity_kind_tree_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="farming_activity_kind_view_tree"/>
<field name="act_window" ref="act_farming_activity_kind_tree"/>
</record>
<record model="ir.action.act_window.view" id="act_farming_activity_kind_tree_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="farming_activity_kind_view_form"/>
<field name="act_window" ref="act_farming_activity_kind_tree"/>
</record>
<!-- <record model="ir.action.act_window" id="act_farming_activity_kind_form">
<field name="name">Activity Kind</field>
<field name="res_model">farming.activity.kind</field>
</record>
<record model="ir.action.act_window.view" id="act_farming_activity_kind_form_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="farming_activity_kind_view_tree"/>
<field name="act_window" ref="act_farming_activity_kind_form"/>
</record>
<record model="ir.action.act_window.view" id="act_farming_activity_kind_form_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="farming_activity_kind_view_form"/>
<field name="act_window" ref="act_farming_activity_kind_form"/>
</record> -->
<menuitem parent="menu_farming" sequence="2"
action="act_farming_activity_kind_tree" id="menu_farming_activity_kind_tree"/>
<record model="ir.ui.view" id="farming_production_view_form">
<field name="model">farming.production</field>
<field name="type">form</field>
<field name="name">production_form</field>
</record>
<record model="ir.ui.view" id="farming_production_view_tree">
<field name="model">farming.production</field>
<field name="type">tree</field>
<field name="name">production_tree</field>
</record>
<record model="ir.action.act_window" id="act_farming_production_form">
<field name="name">Farming Production</field>
<field name="res_model">farming.production</field>
<field name="search_value"></field>
</record>
<record model="ir.action.act_window.view" id="act_farming_production_form_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="farming_production_view_tree"/>
<field name="act_window" ref="act_farming_production_form"/>
</record>
<record model="ir.action.act_window.view" id="act_farming_production_form_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="farming_production_view_form"/>
<field name="act_window" ref="act_farming_production_form"/>
</record>
<record model="ir.action.act_window.domain"
id="act_production_farming_form_domain_draft">
<field name="name">Draft</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('state', '=', 'draft')]" pyson="1"/>
<field name="act_window" ref="act_farming_production_form"/>
</record>
<record model="ir.action.act_window.domain"
id="act_production_farming_form_domain_production_farming">
<field name="name">Production</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('state', '=', 'production')]" pyson="1"/>
<field name="act_window" ref="act_farming_production_form"/>
</record>
<record model="ir.action.act_window.domain"
id="act_production_farming_form_domain_finished">
<field name="name">Finished</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('state', '=', 'finished')]" pyson="1"/>
<field name="act_window" ref="act_farming_production_form"/>
</record>
<record model="ir.action.act_window.domain"
id="act_production_farming_form_domain_all">
<field name="name">All</field>
<field name="sequence" eval="100"/>
<field name="domain"></field>
<field name="act_window" ref="act_farming_production_form"/>
</record>
<menuitem parent="menu_farming" sequence="20"
action="act_farming_production_form"
id="menu_production_farming_form"/>
<!-- Buttons -->
<record model="ir.model.button" id="production_farming_cancel_button">
<field name="name">cancel</field>
<field name="model" search="[('model', '=', 'farming.production')]"/>
</record>
<record model="ir.model.button-res.group"
id="farming_production_cancel_button_group_farming">
<field name="button" ref="production_farming_cancel_button"/>
<field name="group" ref="farming.group_farming"/>
</record>
<record model="ir.model.button" id="farming_production_production_button">
<field name="name">production</field>
<field name="model" search="[('model', '=', 'farming.production')]"/>
</record>
<record model="ir.model.button-res.group"
id="farming_production_production_button_group_farming">
<field name="button" ref="farming_production_production_button"/>
<field name="group" ref="farming.group_farming"/>
</record>
<record model="ir.model.button" id="farming_production_finish_button">
<field name="name">finish</field>
<field name="model" search="[('model', '=', 'farming.production')]"/>
</record>
<record model="ir.model.button-res.group" id="farming_production_finish_button_group_farming">
<field name="button" ref="farming_production_finish_button"/>
<field name="group" ref="farming.group_farming"/>
</record>
<record model="ir.model.access" id="access_farming_activity_kind">
<field name="model" search="[('model', '=', 'farming.activity.kind')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_farming_farming_activity_kind_admin">
<field name="model" search="[('model', '=', 'farming.activity.kind')]"/>
<field name="group" ref="group_farming_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.model.access" id="access_production_farming">
<field name="model" search="[('model', '=', 'farming.production')]"/>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_production_farming_group_farming">
<field name="model" search="[('model', '=', 'farming.production')]"/>
<field name="group" ref="group_farming"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_production_farming_group_farming_admin">
<field name="model" search="[('model', '=', 'farming.production')]"/>
<field name="group" ref="group_farming_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.ui.view" id="activity_view_tree">
<field name="model">farming.activity</field>
<field name="type">tree</field>
<field name="priority">10</field>
<field name="name">activity_tree</field>
</record>
<record model="ir.ui.view" id="activity_view_form">
<field name="model">farming.activity</field>
<field name="type">form</field>
<field name="name">activity_form</field>
</record>
<record model="ir.action.act_window" id="act_activity_tree">
<field name="name">Activity</field>
<field name="res_model">farming.activity</field>
</record>
<record model="ir.action.act_window.view" id="act_activity_tree_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="activity_view_tree"/>
<field name="act_window" ref="act_activity_tree"/>
</record>
<record model="ir.action.act_window.view" id="act_activity_tree_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="activity_view_form"/>
<field name="act_window" ref="act_activity_tree"/>
</record>
<menuitem parent="farming.menu_farming" sequence="20"
action="act_activity_tree" id="menu_activity_tree"/>
<record model="ir.model.access" id="access_farming_activity">
<field name="model" search="[('model', '=', 'farming.activity')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_farming_activity_admin">
<field name="model" search="[('model', '=', 'farming.activity')]"/>
<field name="group" ref="group_farming_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
</data>
</tryton>

View File

@ -1,304 +1,113 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from __future__ import with_statement
from decimal import Decimal
from datetime import date
from trytond.model import Workflow, ModelView, ModelSQL, fields
from trytond.pyson import Eval, If, In, Get
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.exceptions import UserError
from trytond.model import fields, ModelView
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval
# from trytond.transaction import Transaction
# from trytond.wizard import Wizard, StateReport, StateView, Button
# from trytond.report import Report
# from trytond.i18n import gettext
STATES = {
'readonly': (Eval('state') != 'draft'),
'readonly': ~Eval('state').in_(['draft', 'request']),
}
class Kind(ModelSQL, ModelView):
"Kind"
__name__ = "farming.activity.kind"
name = fields.Char('Name', required=True)
activity_time = fields.Float('Act. Time', required=True)
class Production(metaclass=PoolMeta):
__name__ = 'purchase.purchase'
customer = fields.Many2One('party.party', 'Customer', states=STATES)
delivery_date = fields.Date('Delivery Date', states=STATES)
delivery_time = fields.Time('Delivery Time', states=STATES)
@classmethod
def __setup__(cls):
super(Kind, cls).__setup__()
cls._order.insert(0, ('name', 'ASC'))
# @fields.depends('ica_certicate')
# def on_change_ica_certicate(self):
# if self.ica_certicate:
# party = self.ica_certicate.party
# self.party = party.id
# self.invoice_address = party.addresses[0].id
# if party.currency:
# self.currency = party.currency.id
class FarmingProduction(Workflow, ModelSQL, ModelView):
'Farming Production'
__name__ = 'farming.production'
_rec_name = 'number'
number = fields.Char('Number', readonly=True)
product = fields.Many2One('product.product', 'Product', required=True,
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')
quantity_produced = fields.Float('Quantity Produced', states=STATES)
quantity_produced_uom = fields.Many2One('product.uom', 'Quantity UoM', states=STATES)
activities = fields.One2Many('farming.activity', 'production', 'Activities', states=STATES)
lot = fields.Char('Lot', states=STATES)
seed = fields.Char('Seed', required=True, states=STATES)
description = fields.Char('Description', states=STATES)
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):
super(FarmingProduction, cls).__setup__()
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',
},
'production': {
'invisible': Eval('state').in_(['cancelled', 'finished']),
},
'finished': {
'invisible': Eval('state') != 'production',
},
})
@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()
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})
def get_production_time(self, name):
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
class Activity(Workflow, ModelSQL, ModelView):
'Activity'
__name__ = 'farming.activity'
_rec_name = 'kind'
sequence = fields.Char('Sequence', states=STATES)
production = fields.Many2One('farming.production', 'Production', states=STATES)
employee = fields.Many2One('party.party', 'Employee', states=STATES, select=True)
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)
works = fields.One2Many('farming.production.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')
@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
class FarmingWork(ModelSQL, ModelView):
'Farming Work'
__name__ = 'farming.production.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'
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)
# class PurchaseLine(metaclass=PoolMeta):
# __name__ = 'purchase.line'
# STATES = {
# 'invisible': ~Eval('farming'),
# }
# farming = fields.Boolean('Farming')
# capuchon = fields.Selection([
# ('', ''),
# ('si', 'Si'),
# ('no', 'No'),
# ], 'Capuchon', states=STATES)
# patin = fields.Selection([
# ('', ''),
# ('si', 'Si'),
# ('no', 'No'),
# ], 'Patin', states=STATES)
# longitud = fields.Integer('Longitud', states=STATES)
# quality_analysis = fields.One2Many('farming.quality.analysis', 'origin',
# 'Quality Analysis', states=STATES)
#
#
# class PurchaseFarmingStart(ModelView):
# 'Purchase Farming Report Start'
# __name__ = 'farming.purchase.start'
# company = fields.Many2One('company.company', 'Company', required=True)
# start_date = fields.Date("Start Date", required=True)
# end_date = fields.Date("End Date", required=True)
#
# @staticmethod
# def default_company():
# return Transaction().context.get('company')
#
# @staticmethod
# def default_end_date():
# Date = Pool().get('ir.date')
# return Date.today()
#
#
# class PurchaseFarming(Wizard):
# 'Purchase Analytic Report'
# __name__ = 'farming.purchase'
# start = StateView('farming.purchase.start',
# 'farming.farming_purchase_start_view_form', [
# Button('Cancel', 'end', 'tryton-cancel'),
# Button('Print', 'print_', 'tryton-ok', default=True),
# ])
# print_ = StateReport('farming.purchase.report')
#
# def do_print_(self, action):
# data = {
# 'company': self.start.company.id,
# 'start_date': self.start.start_date,
# 'end_date': self.start.end_date,
# }
# return action, data
#
# def transition_print_(self):
# return 'end'
#
#
# class PurchaseFarmingReport(Report):
# __name__ = 'farming.purchase.report'
#
# @classmethod
# def get_context(cls, records, header, data):
# report_context = super().get_context(records, header, data)
# pool = Pool()
# Company = pool.get('company.company')
# Purchase = pool.get('purchase.purchase')
# purchases = Purchase.search([
# ('company', '=', data['company']),
# ('lines.farming', '=', True),
# ('lines.quantity', '>=', 0),
# ('ica_certicate', '!=', None),
# ('purchase_date', '>=', data['start_date']),
# ('purchase_date', '<=', data['end_date']),
# ], order=[('purchase_date', 'ASC')])
#
# report_context['records'] = purchases
# report_context['company'] = Company(data['company'])
# return report_context

View File

@ -3,225 +3,35 @@
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="farming_work_view_tree">
<field name="model">farming.production.work</field>
<field name="type">tree</field>
<field name="name">farming_work_tree</field>
</record>
<record model="ir.ui.view" id="farming_work_view_form">
<field name="model">farming.production.work</field>
<field name="type">form</field>
<field name="name">farming_work_form</field>
</record>
<record model="ir.ui.view" id="farming_activity_kind_view_tree">
<field name="model">farming.activity.kind</field>
<field name="type">tree</field>
<field name="name">farming_activity_kind_tree</field>
</record>
<record model="ir.ui.view" id="farming_activity_kind_view_form">
<field name="model">farming.activity.kind</field>
<field name="type">form</field>
<field name="name">farming_activity_kind_form</field>
</record>
<record model="ir.action.act_window" id="act_farming_activity_kind_tree">
<field name="name">Activity Kind</field>
<field name="res_model">farming.activity.kind</field>
</record>
<record model="ir.action.act_window.view" id="act_farming_activity_kind_tree_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="farming_activity_kind_view_tree"/>
<field name="act_window" ref="act_farming_activity_kind_tree"/>
</record>
<record model="ir.action.act_window.view" id="act_farming_activity_kind_tree_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="farming_activity_kind_view_form"/>
<field name="act_window" ref="act_farming_activity_kind_tree"/>
</record>
<!-- <record model="ir.action.act_window" id="act_farming_activity_kind_form">
<field name="name">Activity Kind</field>
<field name="res_model">farming.activity.kind</field>
</record>
<record model="ir.action.act_window.view" id="act_farming_activity_kind_form_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="farming_activity_kind_view_tree"/>
<field name="act_window" ref="act_farming_activity_kind_form"/>
</record>
<record model="ir.action.act_window.view" id="act_farming_activity_kind_form_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="farming_activity_kind_view_form"/>
<field name="act_window" ref="act_farming_activity_kind_form"/>
<record model="ir.ui.view" id="production_view_form">
<field name="model">production</field>
<field name="inherit" ref="production.production_view_form"/>
<field name="name">production_form</field>
</record>
<!-- <record model="ir.ui.view" id="production_line_view_form">
<field name="model">production.line</field>
<field name="inherit" ref="production.production_line_view_form"/>
<field name="name">production_line_form</field>
</record> -->
<menuitem parent="menu_farming" sequence="2"
action="act_farming_activity_kind_tree" id="menu_farming_activity_kind_tree"/>
<record model="ir.ui.view" id="production_view_form">
<field name="model">farming.production</field>
<field name="type">form</field>
<field name="name">production_form</field>
</record>
<record model="ir.ui.view" id="production_view_tree">
<field name="model">farming.production</field>
<field name="type">tree</field>
<field name="name">production_tree</field>
</record>
<record model="ir.action.act_window" id="act_production_farming_form">
<field name="name">Farming Production</field>
<field name="res_model">farming.production</field>
<field name="search_value"></field>
</record>
<record model="ir.action.act_window.view" id="act_production_farming_form_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="production_view_tree"/>
<field name="act_window" ref="act_production_farming_form"/>
</record>
<record model="ir.action.act_window.view" id="act_production_farming_form_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="production_view_form"/>
<field name="act_window" ref="act_production_farming_form"/>
</record>
<record model="ir.action.act_window.domain" id="act_production_farming_form_domain_draft">
<field name="name">Draft</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('state', '=', 'draft')]" pyson="1"/>
<field name="act_window" ref="act_production_farming_form"/>
</record>
<record model="ir.action.act_window.domain" id="act_production_farming_form_domain_production_farming">
<field name="name">Production</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('state', '=', 'production')]" pyson="1"/>
<field name="act_window" ref="act_production_farming_form"/>
</record>
<record model="ir.action.act_window.domain" id="act_production_farming_form_domain_finished">
<field name="name">Finished</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('state', '=', 'finished')]" pyson="1"/>
<field name="act_window" ref="act_production_farming_form"/>
</record>
<record model="ir.action.act_window.domain" id="act_production_farming_form_domain_all">
<field name="name">All</field>
<field name="sequence" eval="100"/>
<field name="domain"></field>
<field name="act_window" ref="act_production_farming_form"/>
</record>
<menuitem parent="menu_farming" sequence="20"
action="act_production_farming_form" id="menu_production_farming_form"/>
<!-- Buttons -->
<record model="ir.model.button" id="production_farming_cancel_button">
<field name="name">cancel</field>
<field name="model" search="[('model', '=', 'farming.production')]"/>
</record>
<record model="ir.model.button-res.group" id="farming_production_cancel_button_group_farming">
<field name="button" ref="production_farming_cancel_button"/>
<field name="group" ref="farming.group_farming"/>
</record>
<record model="ir.model.button" id="farming_production_production_button">
<field name="name">production</field>
<field name="model" search="[('model', '=', 'farming.production')]"/>
</record>
<record model="ir.model.button-res.group" id="farming_production_production_button_group_farming">
<field name="button" ref="farming_production_production_button"/>
<field name="group" ref="farming.group_farming"/>
</record>
<record model="ir.model.button" id="farming_production_finish_button">
<field name="name">finish</field>
<field name="model" search="[('model', '=', 'farming.production')]"/>
</record>
<record model="ir.model.button-res.group" id="farming_production_finish_button_group_farming">
<field name="button" ref="farming_production_finish_button"/>
<field name="group" ref="farming.group_farming"/>
</record>
<record model="ir.model.access" id="access_farming_activity_kind">
<field name="model" search="[('model', '=', 'farming.activity.kind')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_farming_farming_activity_kind_admin">
<field name="model" search="[('model', '=', 'farming.activity.kind')]"/>
<field name="group" ref="group_farming_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.model.access" id="access_production_farming">
<field name="model" search="[('model', '=', 'farming.production')]"/>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_production_farming_group_farming">
<field name="model" search="[('model', '=', 'farming.production')]"/>
<field name="group" ref="group_farming"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_production_farming_group_farming_admin">
<field name="model" search="[('model', '=', 'farming.production')]"/>
<field name="group" ref="group_farming_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.ui.view" id="activity_view_tree">
<field name="model">farming.activity</field>
<field name="type">tree</field>
<field name="priority">10</field>
<field name="name">activity_tree</field>
</record>
<record model="ir.ui.view" id="activity_view_form">
<field name="model">farming.activity</field>
<field name="type">form</field>
<field name="name">activity_form</field>
</record>
<record model="ir.action.act_window" id="act_activity_tree">
<field name="name">Activity</field>
<field name="res_model">farming.activity</field>
</record>
<record model="ir.action.act_window.view" id="act_activity_tree_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="activity_view_tree"/>
<field name="act_window" ref="act_activity_tree"/>
</record>
<record model="ir.action.act_window.view" id="act_activity_tree_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="activity_view_form"/>
<field name="act_window" ref="act_activity_tree"/>
</record>
<menuitem parent="farming.menu_farming" sequence="20"
action="act_activity_tree" id="menu_activity_tree"/>
<record model="ir.model.access" id="access_farming_activity">
<field name="model" search="[('model', '=', 'farming.activity')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_farming_activity_admin">
<field name="model" search="[('model', '=', 'farming.activity')]"/>
<field name="group" ref="group_farming_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<!--
<record model="ir.action.report" id="report_farming_production">
<field name="name">production Farming Report</field>
<field name="model"></field>
<field name="report_name">farming.production.report</field>
<field name="report">farming/production_report.fods</field>
</record>
<record model="ir.ui.view" id="farming_production_start_view_form">
<field name="model">farming.production.start</field>
<field name="type">form</field>
<field name="name">farming_production_start_form</field>
</record>
<record model="ir.action.wizard" id="wizard_print_farming_production_report">
<field name="name">production Farming Report</field>
<field name="wiz_name">farming.production</field>
</record>
<menuitem name="productions Farming" parent="farming.menu_reports"
sequence="2" id="menu_farming_production_report"
action="wizard_print_farming_production_report"/> -->
</data>
</tryton>

View File

@ -13,24 +13,24 @@ this repository contains the full copyright notices and license terms. -->
<field name="inherit" ref="purchase.purchase_line_view_form"/>
<field name="name">purchase_line_form</field>
</record>
</data>
<record model="ir.action.report" id="report_farming_purchase">
<field name="name">Purchase Farming Report</field>
<field name="model"></field>
<field name="report_name">farming.purchase.report</field>
<field name="report">farming/purchase_report.fods</field>
</record>
<record model="ir.ui.view" id="farming_purchase_start_view_form">
<field name="model">farming.purchase.start</field>
<field name="type">form</field>
<field name="name">farming_purchase_start_form</field>
</record>
<record model="ir.action.wizard" id="wizard_print_farming_purchase_report">
<field name="name">Purchase Farming Report</field>
<field name="wiz_name">farming.purchase</field>
</record>
<menuitem name="Purchases Farming" parent="farming.menu_reports"
sequence="2" id="menu_farming_purchase_report"
action="wizard_print_farming_purchase_report"/>
<record model="ir.action.report" id="report_farming_purchase">
<field name="name">Purchase Farming Report</field>
<field name="model"></field>
<field name="report_name">farming.purchase.report</field>
<field name="report">farming/purchase_report.fods</field>
</record>
<record model="ir.ui.view" id="farming_purchase_start_view_form">
<field name="model">farming.purchase.start</field>
<field name="type">form</field>
<field name="name">farming_purchase_start_form</field>
</record>
<record model="ir.action.wizard" id="wizard_print_farming_purchase_report">
<field name="name">Purchase Farming Report</field>
<field name="wiz_name">farming.purchase</field>
</record>
<menuitem name="Purchases Farming" parent="farming.menu_reports"
sequence="2" id="menu_farming_purchase_report"
action="wizard_print_farming_purchase_report"/>
</data>
</tryton>

15
sale.py
View File

@ -18,6 +18,21 @@ class Sale(metaclass=PoolMeta):
MAWB = fields.Char('MAWB')
HAWB = fields.Char('HAWB')
@classmethod
def proceed(cls, sales):
return super(Sale, cls).proceed(sales)
for sale in sales:
for line in sale.lines:
if line.product.producible:
cls.create_productions(line)
@classmethod
def create_productions(cls, line):
cls.create_order(line.product)
# @classmethod
# def create_productions(cls, sale):
class SaleLine(metaclass=PoolMeta):
__name__ = 'sale.line'

View File

@ -1,5 +1,5 @@
[tryton]
version=6.0.1
version=6.0.2
depends:
party
company
@ -13,8 +13,9 @@ xml:
farming.xml
configuration.xml
location.xml
production.xml
farm_production.xml
quality.xml
purchase.xml
sale.xml
product.xml
production.xml

View File

@ -0,0 +1,64 @@
<?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="product"/>
<field name="product"/>
<label name="number"/>
<field name="number"/>
<label name="location"/>
<field name="location"/>
<label name="seed"/>
<field name="seed"/>
<label name="start_date"/>
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
<label name="lot"/>
<field name="lot"/>
<label name="description"/>
<field name="description"/>
<group id="quantity" col="6" colspan="4">
<label name="field_size"/>
<field name="field_size"/>
<label name="quantity_produced"/>
<field name="quantity_produced"/>
<label name="quantity_produced_uom"/>
<field name="quantity_produced_uom"/>
</group>
<notebook colspan="4">
<page string="Indicators" col="2" id="indicators">
<field name="activities" colspan="4"/>
</page>
<page string="Indicators" col="2" id="indicators">
<label name="production_time"/>
<field name="production_time"/>
<label name="production_cost"/>
<field name="production_cost"/>
<label name="performance"/>
<field name="performance"/>
<label name="gross_profit_rate"/>
<field name="gross_profit_rate"/>
<label name="gross_profit"/>
<field name="gross_profit"/>
</page>
<page string="Additional Info" col="2" id="indicators">
<label name="company"/>
<field name="company"/>
</page>
</notebook>
<group col="6" colspan="4" id="state_buttons">
<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"/>
</group>
</group>
</form>

View File

@ -1,64 +1,15 @@
<?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="product"/>
<field name="product"/>
<label name="number"/>
<field name="number"/>
<label name="location"/>
<field name="location"/>
<label name="seed"/>
<field name="seed"/>
<label name="start_date"/>
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
<label name="lot"/>
<field name="lot"/>
<label name="description"/>
<field name="description"/>
<group id="quantity" col="6" colspan="4">
<label name="field_size"/>
<field name="field_size"/>
<label name="quantity_produced"/>
<field name="quantity_produced"/>
<label name="quantity_produced_uom"/>
<field name="quantity_produced_uom"/>
</group>
<notebook colspan="4">
<page string="Indicators" col="2" id="indicators">
<field name="activities" colspan="4"/>
</page>
<page string="Indicators" col="2" id="indicators">
<label name="production_time"/>
<field name="production_time"/>
<label name="production_cost"/>
<field name="production_cost"/>
<label name="performance"/>
<field name="performance"/>
<label name="gross_profit_rate"/>
<field name="gross_profit_rate"/>
<label name="gross_profit"/>
<field name="gross_profit"/>
</page>
<page string="Additional Info" col="2" id="indicators">
<label name="company"/>
<field name="company"/>
</page>
</notebook>
<group col="6" colspan="4" id="state_buttons">
<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"/>
</group>
</group>
</form>
<!-- This file is part of sale_pos module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath
expr="/form/field[@name='uom']" position="after">
<label name="customer"/>
<field name="customer"/>
<label name="delivery_date"/>
<field name="delivery_date"/>
<label name="delivery_time"/>
<field name="delivery_time"/>
</xpath>
</data>