Add sequence for cost plan numbering.

This commit is contained in:
Albert Cervera i Areny 2014-03-16 04:07:48 +01:00
parent ccc9d9b02b
commit a8f575279b
8 changed files with 86 additions and 3 deletions

View File

@ -3,6 +3,7 @@
from trytond.pool import Pool
from .plan import *
from .configuration import *
def register():
Pool.register(
@ -11,4 +12,5 @@ def register():
PlanProductLine,
PlanCostType,
PlanCost,
Configuration,
module='product_cost_plan', type_='model')

19
configuration.py Normal file
View File

@ -0,0 +1,19 @@
#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.model import fields
from trytond.pyson import Eval
from trytond.pool import PoolMeta
__all__ = ['Configuration']
__metaclass__ = PoolMeta
class Configuration:
__name__ = 'production.configuration'
product_cost_plan_sequence = fields.Property(fields.Many2One('ir.sequence',
'Product Cost Plan Sequence', domain=[
('company', 'in',
[Eval('context', {}).get('company', -1), None]),
('code', '=', 'product_cost_plan'),
], required=True))

19
configuration.xml Normal file
View File

@ -0,0 +1,19 @@
<?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="production_configuration_view_form">
<field name="model">production.configuration</field>
<field name="type">form</field>
<field name="name">configuration_form</field>
<field name="inherit" ref="production.production_configuration_view_form"/>
</record>
<record model="ir.property" id="property_product_cost_plan_sequence">
<field name="field"
search="[('model.model', '=', 'production.configuration'), ('name', '=', 'product_cost_plan_sequence')]"/>
<field name="value" eval="'ir.sequence,' + str(ref('sequence_product_cost_plan'))"/>
</record>
</data>
</tryton>

16
plan.py
View File

@ -17,7 +17,7 @@ class Plan(Workflow, ModelSQL, ModelView):
'Product Cost Plan'
__name__ = 'product.cost.plan'
number = fields.Char('Number')
number = fields.Char('Number', select=True, readonly=True)
active = fields.Boolean('Active')
product = fields.Many2One('product.product', 'Product',
states={
@ -149,6 +149,18 @@ class Plan(Workflow, ModelSQL, ModelView):
def on_change_with_cost_price(self, name=None):
return sum(c.cost for c in self.costs if c.cost)
@classmethod
def create(cls, vlist):
Sequence = Pool().get('ir.sequence')
Config = Pool().get('production.configuration')
vlist = [x.copy() for x in vlist]
config = Config(1)
for values in vlist:
values['number'] = Sequence.get_id(
config.product_cost_plan_sequence.id)
return super(Plan, cls).create(vlist)
@classmethod
@ModelView.button
@Workflow.transition('draft')
@ -195,7 +207,7 @@ class Plan(Workflow, ModelSQL, ModelView):
CostLines.create(costs_to_create)
def get_costs(self):
" Returns the cost lines to be created on compute "
"Returns the cost lines to be created on compute"
ret = []
for cost_type, field_name in self.get_cost_types():
ret.append(self.get_cost_line(cost_type, field_name))

View File

@ -24,6 +24,27 @@
<field name="user" ref="res.user_trigger"/>
<field name="group" ref="group_product_cost_plan"/>
</record>
<record model="ir.sequence.type" id="sequence_type_product_cost_plan">
<field name="name">Product Cost Plan</field>
<field name="code">product_cost_plan</field>
</record>
<record model="ir.sequence.type-res.group"
id="sequence_type_product_cost_plan_group_admin">
<field name="sequence_type" ref="sequence_type_product_cost_plan"/>
<field name="group" ref="res.group_admin"/>
</record>
<record model="ir.sequence.type-res.group"
id="sequence_type_product_cost_plan_group_production_admin">
<field name="sequence_type" ref="sequence_type_product_cost_plan"/>
<field name="group" ref="group_product_cost_plan_admin"/>
</record>
<record model="ir.sequence" id="sequence_product_cost_plan">
<field name="name">Product Cost Plan</field>
<field name="code">product_cost_plan</field>
</record>
<record model="ir.ui.view" id="product_cost_plan_view_form">
<field name="model">product.cost.plan</field>
<field name="type">form</field>

View File

@ -4,3 +4,4 @@ depends:
production
xml:
plan.xml
configuration.xml

View File

@ -0,0 +1,9 @@
<?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/field[@name='production_sequence']" position="after">
<label name="product_cost_plan_sequence"/>
<field name="product_cost_plan_sequence"/>
</xpath>
</data>

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<form string="Product Cost Plan" col="6">
<form string="Product Cost Plan" col="6" cursor="product">
<label name="number"/>
<field name="number"/>
<label name="active"/>