Add direct cost

This commit is contained in:
Oscar 2022-01-19 09:20:57 -05:00
parent 7a49d72ca5
commit 69b49ba7d7
8 changed files with 83 additions and 10 deletions

View File

@ -1,11 +1,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.
from trytond.pool import Pool
from . import production
from . import account
from . import stock
from . import ir
from . import bom
import production
import account
import stock
import ir
import bom
def register():
@ -16,6 +16,7 @@ def register():
production.ProductionDetailedStart,
ir.Cron,
bom.BOM,
bom.BOMDirectCost,
module='production_accounting', type_='model')
Pool.register(
production.ProductionDetailed,

26
bom.py
View File

@ -1,15 +1,18 @@
# 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 trytond.pool import Pool, PoolMeta
from decimal import Decimal
from datetime import datetime, date
from trytond.pool import Pool, PoolMeta
from trytond.modules.product import round_price
from trytond.transaction import Transaction
from datetime import datetime, date
from trytond.model import fields, ModelSQL, ModelView
class BOM(metaclass=PoolMeta):
"Bill of Material"
__name__ = 'production.bom'
direct_costs = fields.One2Many('production.bom.direct_cost',
'bom', 'Direct Costs')
@classmethod
def calc_cost_ldm(cls):
@ -52,3 +55,20 @@ class BOM(metaclass=PoolMeta):
cost += (Decimal(str(quantity)) * cost_price)
return round_price(cost)
class BOMDirectCost(ModelSQL, ModelView):
"BOMDirectCost"
__name__ = "production.bom.direct_cost"
bom = fields.Many2One('production.bom', 'BOM', required=True,
ondelete='CASCADE')
product = fields.Many2One('product.product', 'Product', required=True,
domain=[('type', '!=', 'active')])
uom = fields.Many2One('product.uom', 'UoM')
quantity = fields.Float('Quantity', required=True, digits=(16,2))
notes = fields.Char('Notes')
@fields.depends('product', 'uom')
def on_change_with_uom(self, name=None):
if self.product:
return self.product.default_uom.id

24
bom.xml Normal file
View File

@ -0,0 +1,24 @@
<?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="bom_view_form">
<field name="model">production.bom</field>
<field name="inherit" ref="production.bom_view_form"/>
<field name="name">bom_form</field>
</record>
<record model="ir.ui.view" id="bom_direct_cost_view_form">
<field name="model">production.bom.direct_cost</field>
<field name="type">form</field>
<field name="name">bom_direct_cost_form</field>
</record>
<record model="ir.ui.view" id="bom_direct_cost_view_tree">
<field name="model">production.bom.direct_cost</field>
<field name="type">tree</field>
<field name="name">bom_direct_cost_tree</field>
</record>
</data>
</tryton>

View File

@ -1,5 +1,5 @@
[tryton]
version=6.0.2
version=6.0.3
depends:
party
company
@ -11,3 +11,4 @@ xml:
message.xml
production.xml
product.xml
bom.xml

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<form>
<label name="product"/>
<field name="product"/>
<label name="uom"/>
<field name="uom"/>
<label name="quantity"/>
<field name="quantity"/>
<label name="notes"/>
<field name="notes"/>
</form>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<tree>
<field name="product"/>
<field name="uom"/>
<field name="quantity"/>
<field name="notes"/>
</tree>

10
view/bom_form.xml Normal file
View 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. -->
<data>
<xpath expr="/form/notebook/page[@id='lines']" position="after">
<page string="Related Costs" id="page_related_costs">
<field name="direct_costs" colspan="4"/>
</page>
</xpath>
</data>

View File

@ -22,5 +22,4 @@ this repository contains the full copyright notices and license terms. -->
<label name="effective_start_date"/>
<field name="effective_start_date"/>
</xpath>
</data>