From a8f575279b33f09f8ae8f3cf0c5dd5a7f8482849 Mon Sep 17 00:00:00 2001 From: Albert Cervera i Areny Date: Sun, 16 Mar 2014 04:07:48 +0100 Subject: [PATCH] Add sequence for cost plan numbering. --- __init__.py | 2 ++ configuration.py | 19 +++++++++++++++++++ configuration.xml | 19 +++++++++++++++++++ plan.py | 16 ++++++++++++++-- plan.xml | 21 +++++++++++++++++++++ tryton.cfg | 1 + view/configuration_form.xml | 9 +++++++++ view/cost_plan_form.xml | 2 +- 8 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 configuration.py create mode 100644 configuration.xml create mode 100644 view/configuration_form.xml diff --git a/__init__.py b/__init__.py index 5fc7455..f606537 100644 --- a/__init__.py +++ b/__init__.py @@ -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') diff --git a/configuration.py b/configuration.py new file mode 100644 index 0000000..5a157e5 --- /dev/null +++ b/configuration.py @@ -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)) diff --git a/configuration.xml b/configuration.xml new file mode 100644 index 0000000..ca64425 --- /dev/null +++ b/configuration.xml @@ -0,0 +1,19 @@ + + + + + + production.configuration + form + configuration_form + + + + + + + + + diff --git a/plan.py b/plan.py index 6d051b0..73aae8e 100644 --- a/plan.py +++ b/plan.py @@ -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)) diff --git a/plan.xml b/plan.xml index 6e3106d..67d3800 100644 --- a/plan.xml +++ b/plan.xml @@ -24,6 +24,27 @@ + + + Product Cost Plan + product_cost_plan + + + + + + + + + + + + Product Cost Plan + product_cost_plan + + product.cost.plan form diff --git a/tryton.cfg b/tryton.cfg index f53f7ec..020b802 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -4,3 +4,4 @@ depends: production xml: plan.xml + configuration.xml diff --git a/view/configuration_form.xml b/view/configuration_form.xml new file mode 100644 index 0000000..642b2c3 --- /dev/null +++ b/view/configuration_form.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/view/cost_plan_form.xml b/view/cost_plan_form.xml index be8074a..68bda4e 100644 --- a/view/cost_plan_form.xml +++ b/view/cost_plan_form.xml @@ -1,7 +1,7 @@ -
+