mirror of
https://bitbucket.org/presik/trytonpsk-production_accounting.git
synced 2023-12-14 05:22:54 +01:00
Add subproduction
This commit is contained in:
parent
29909265ee
commit
f3d53ad312
11 changed files with 1430 additions and 2 deletions
|
@ -19,6 +19,8 @@ def register():
|
|||
production.ProductionDetailedStart,
|
||||
production.ProcessProductionAsyncStart,
|
||||
production.ProductionCost,
|
||||
production.SubProduction,
|
||||
production.SubProductionIn,
|
||||
account.Move,
|
||||
stock.Move,
|
||||
ir.Cron,
|
||||
|
|
1
bom.py
1
bom.py
|
@ -12,6 +12,7 @@ class BOM(metaclass=PoolMeta):
|
|||
__name__ = 'production.bom'
|
||||
direct_costs = fields.One2Many('production.bom.direct_cost', 'bom',
|
||||
'Direct Costs')
|
||||
is_subproduction = fields.Boolean('Is Subproduction')
|
||||
|
||||
@classmethod
|
||||
def calc_cost_ldm(cls):
|
||||
|
|
1261
materials_forecast.fods
Normal file
1261
materials_forecast.fods
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,7 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# 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 decimal import Decimal
|
||||
from datetime import date
|
||||
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.model import fields, ModelView, ModelSQL
|
||||
|
@ -23,6 +24,40 @@ def round_dec(number):
|
|||
return Decimal(number.quantize(Decimal('.01')))
|
||||
|
||||
|
||||
class SubProduction(ModelSQL, ModelView):
|
||||
"Sub Production"
|
||||
__name__ = "production.sub"
|
||||
production = fields.Many2One('production', 'Production', required=True,
|
||||
ondelete='CASCADE')
|
||||
product = fields.Many2One('product.product', 'Product', required=True)
|
||||
effective_date = fields.Date('Effect. Date', required=True)
|
||||
quantity = fields.Float('Quantity', required=True)
|
||||
inputs = fields.One2Many('production.sub.in', 'sub', 'Sub. Inputs')
|
||||
employee = fields.Many2One('company.employee', 'Employee')
|
||||
state = fields.Selection([
|
||||
('draft', 'Draft'),
|
||||
('in_progress', 'In progress'),
|
||||
('finished', 'Finished'),
|
||||
('cancelled', 'Canceled'),
|
||||
], 'State', select=True)
|
||||
notes = fields.Char('Notes')
|
||||
|
||||
@staticmethod
|
||||
def default_effective_date():
|
||||
return date.today()
|
||||
|
||||
|
||||
class SubProductionIn(ModelSQL, ModelView):
|
||||
"Sub Production In"
|
||||
__name__ = "production.sub.in"
|
||||
sub = fields.Many2One('production.sub', 'Production Sub', required=True,
|
||||
ondelete='CASCADE')
|
||||
product = fields.Many2One('product.product', 'product', required=True)
|
||||
move = fields.Many2One('stock.move', 'Move')
|
||||
quantity = fields.Float('Quantity', required=True)
|
||||
notes = fields.Char('Notes')
|
||||
|
||||
|
||||
class Production(metaclass=PoolMeta):
|
||||
__name__ = 'production'
|
||||
_analytic_dom = [
|
||||
|
@ -42,6 +77,7 @@ class Production(metaclass=PoolMeta):
|
|||
warehouse_target = fields.Many2One('stock.location', 'Warehouse Target',
|
||||
domain=[('type', '=', 'warehouse')])
|
||||
warehouse_moves = fields.One2Many('stock.move', 'origin', 'Warehouse Moves')
|
||||
subs = fields.One2Many('production.sub', 'production', 'Sub Productions')
|
||||
costs = fields.One2Many('production.cost', 'production', 'Costs')
|
||||
material_costs = fields.Numeric('Material Costs', digits=(16, 2),
|
||||
states={'readonly': True})
|
||||
|
@ -68,6 +104,52 @@ class Production(metaclass=PoolMeta):
|
|||
'Analytic Account Indirect', domain=_analytic_dom)
|
||||
analytic_account_services = fields.Many2One('analytic_account.account',
|
||||
'Analytic Account Services', domain=_analytic_dom)
|
||||
subproductions = fields.One2Many('production.sub', 'production',
|
||||
'Sub-Productions')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Production, cls).__setup__()
|
||||
cls._buttons.update({
|
||||
'generate_sub': {
|
||||
'invisible': Eval('state').in_(['done']),
|
||||
}
|
||||
})
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def generate_sub(cls, records):
|
||||
pool = Pool()
|
||||
BOMOutput = pool.get('production.bom.output')
|
||||
Sub = pool.get('production.sub')
|
||||
to_create = []
|
||||
for pcc in records:
|
||||
for input in pcc.inputs:
|
||||
outputs = BOMOutput.search([
|
||||
('product', '=', input.product.id),
|
||||
('bom.is_subproduction', '=', True),
|
||||
])
|
||||
if not outputs:
|
||||
continue
|
||||
|
||||
output = outputs[0]
|
||||
to_create = {
|
||||
'production': pcc.id,
|
||||
'product': input.product.id,
|
||||
'quantity': input.quantity,
|
||||
'state': 'draft',
|
||||
}
|
||||
|
||||
_inputs_to_create = []
|
||||
for _input in output.bom.inputs:
|
||||
_inputs_to_create.append({
|
||||
'product': _input.product.id,
|
||||
'quantity': _input.quantity * input.quantity,
|
||||
})
|
||||
to_create['inputs'] = [('create', _inputs_to_create)]
|
||||
|
||||
if to_create:
|
||||
Sub.create([to_create])
|
||||
|
||||
@staticmethod
|
||||
def default_warehouse_origin():
|
||||
|
@ -333,7 +415,7 @@ class Production(metaclass=PoolMeta):
|
|||
def on_change_inputs(self, name=None):
|
||||
res = []
|
||||
for _input in self.inputs:
|
||||
quantity = _input.quantity if _input.quantity else 0
|
||||
quantity = _inputsetup.quantity if _input.quantity else 0
|
||||
cost_price = _input.product.cost_price if _input.product else 0
|
||||
res.append(Decimal(quantity) * cost_price)
|
||||
self.material_costs = sum(res)
|
||||
|
|
|
@ -4,6 +4,27 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<tryton>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="production_sub_view_tree">
|
||||
<field name="model">production.sub</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">production_sub_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="production_sub_view_form">
|
||||
<field name="model">production.sub</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">production_sub_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="production_sub_in_view_tree">
|
||||
<field name="model">production.sub.in</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">production_sub_in_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="production_sub_in_view_form">
|
||||
<field name="model">production.sub.in</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">production_sub_in_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="production_view_form">
|
||||
<field name="model">production</field>
|
||||
<field name="inherit" ref="production.production_view_form"/>
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
<!-- This file is part of 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='active']" position="after">
|
||||
<label name="is_subproduction"/>
|
||||
<field name="is_subproduction"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page[@id='lines']" position="after">
|
||||
<page string="Related Costs" id="page_related_costs">
|
||||
<field name="direct_costs" colspan="4"/>
|
||||
|
|
|
@ -20,6 +20,10 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="analytic_account" widget="selection"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page[@id='other']" position="after">
|
||||
<page string="Sub Productions" id="sub_productions">
|
||||
<button name="generate_sub" string="Gen. Subs" icon="tryton-board"/>
|
||||
<field name="subs" colspan="4"/>
|
||||
</page>
|
||||
<page string="Stock Moves" id="warehouse_stock_moves">
|
||||
<field name="warehouse_moves" colspan="4"/>
|
||||
</page>
|
||||
|
|
18
view/production_sub_form.xml
Normal file
18
view/production_sub_form.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?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="effective_date"/>
|
||||
<field name="effective_date"/>
|
||||
<label name="product"/>
|
||||
<field name="product"/>
|
||||
<label name="quantity"/>
|
||||
<field name="quantity"/>
|
||||
<label name="employee"/>
|
||||
<field name="employee"/>
|
||||
<label name="notes"/>
|
||||
<field name="notes"/>
|
||||
<label name="state"/>
|
||||
<field name="state"/>
|
||||
<field name="inputs" colspan="4"/>
|
||||
</form>
|
13
view/production_sub_in_form.xml
Normal file
13
view/production_sub_in_form.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?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="quantity"/>
|
||||
<field name="quantity"/>
|
||||
<label name="notes"/>
|
||||
<field name="notes"/>
|
||||
<label name="move"/>
|
||||
<field name="move"/>
|
||||
</form>
|
10
view/production_sub_in_tree.xml
Normal file
10
view/production_sub_in_tree.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?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. -->
|
||||
<tree editable="1">
|
||||
<field name="effective_date" expand="1"/>
|
||||
<field name="product" expand="1"/>
|
||||
<field name="quantity" expand="1"/>
|
||||
<field name="move" expand="1"/>
|
||||
<field name="notes" expand="1"/>
|
||||
</tree>
|
11
view/production_sub_tree.xml
Normal file
11
view/production_sub_tree.xml
Normal 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. -->
|
||||
<tree editable="1">
|
||||
<field name="effective_date" expand="1"/>
|
||||
<field name="product" expand="1"/>
|
||||
<field name="quantity" expand="1"/>
|
||||
<field name="notes" expand="1"/>
|
||||
<field name="employee" expand="1"/>
|
||||
<field name="state" expand="1"/>
|
||||
</tree>
|
Loading…
Reference in a new issue