Split from sale_cost_plan

This commit is contained in:
Simó Albert i Beltran 2017-12-18 17:19:57 +01:00
parent f458d2cb5e
commit 863dbad3f1
16 changed files with 13 additions and 161 deletions

2
README
View File

@ -14,7 +14,7 @@ questions on the NaN·tic bug tracker, mailing list,
wiki or IRC channel:
* http://doc.tryton-erp.es/
* http://bitbucket.org/nantic/trytond-sale_cost_plan
* http://bitbucket.org/nantic/trytond-sale_supply_production
* http://groups.tryton.org/
* http://wiki.tryton.org/
* irc://irc.freenode.net/tryton

View File

@ -9,13 +9,12 @@ from .sale import *
def register():
Pool.register(
Production,
Plan,
ChangeQuantityStart,
SaleLine,
Sale,
ChangeLineQuantityStart,
module='sale_cost_plan', type_='model')
module='sale_supply_production', type_='model')
Pool.register(
ChangeQuantity,
ChangeLineQuantity,
module='sale_cost_plan', type_='wizard')
module='sale_supply_production', type_='wizard')

View File

@ -40,10 +40,6 @@ msgstr ""
"La línea \"%(line)s\" de la venta \"%(sale)s\" no tiene Plan de coste, por "
"lo que no se generará ninguna producción."
msgctxt "field:production,cost_plan:"
msgid "Cost Plan"
msgstr "Plan de costes"
msgctxt "field:production.change_quantity.start,current_quantity:"
msgid "Current Quantity"
msgstr "Cantidad actual"

View File

@ -13,12 +13,6 @@ __metaclass__ = PoolMeta
class Production:
__name__ = 'production'
cost_plan = fields.Many2One('product.cost.plan', 'Cost Plan',
states={
'readonly': ~Eval('state').in_(['request', 'draft']),
},
depends=['state'])
@classmethod
def _get_origin(cls):
'Return list of Model names for origin Reference'
@ -52,7 +46,7 @@ class ChangeQuantity(Wizard):
__name__ = 'production.change_quantity'
start = StateView('production.change_quantity.start',
'sale_cost_plan.production_change_quantity_start_view_form', [
'sale_supply_production.production_change_quantity_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Modify', 'modify', 'tryton-ok', default=True),
])

View File

@ -1,13 +1,4 @@
<tryton>
<data>
<!-- production -->
<record model="ir.ui.view" id="production_view_form">
<field name="model">production</field>
<field name="type" eval="None"/>
<field name="inherit" ref="production.production_view_form"/>
<field name="name">production_form</field>
</record>
</data>
<data depends="sale_change_quantity">
<!-- production.change_quantity -->
<record model="ir.ui.view" id="production_change_quantity_start_view_form">

96
sale.py
View File

@ -7,8 +7,7 @@ from trytond.transaction import Transaction
from .tools import prepare_vals
__all__ = ['Sale', 'SaleLine', 'Plan',
'ChangeLineQuantityStart', 'ChangeLineQuantity']
__all__ = ['Sale', 'SaleLine', 'ChangeLineQuantityStart', 'ChangeLineQuantity']
__metaclass__ = PoolMeta
@ -65,30 +64,8 @@ class Sale:
class SaleLine:
__name__ = 'sale.line'
cost_plan = fields.Many2One('product.cost.plan', 'Cost Plan',
domain=[
('product', '=', Eval('product', 0)),
],
states={
'invisible': Eval('type') != 'line',
},
depends=['type', 'product'])
productions = fields.One2Many('production', 'origin', 'Productions')
@fields.depends('cost_plan', 'product')
def on_change_product(self):
CostPlan = Pool().get('product.cost.plan')
plan = None
if self.product:
plans = CostPlan.search([('product', '=', self.product.id)],
order=[('number', 'DESC')], limit=1)
if plans:
plan = plans[0]
self.cost_plan = plan
super(SaleLine, self).on_change_product()
if plan:
self.cost_plan = plan
def create_productions(self):
pool = Pool()
try:
@ -164,77 +141,6 @@ class SaleLine:
return super(SaleLine, cls).copy(lines, default=default)
class Plan:
__name__ = 'product.cost.plan'
@classmethod
def __setup__(cls):
super(Plan, cls).__setup__()
cls._error_messages.update({
'cannot_create_productions_missing_bom': ('No production can '
'be created because Product Cost Plan "%s" has no BOM '
'assigned.')
})
def get_elegible_productions(self, unit, quantity):
"""
Returns a list of dicts with the required data to create all the
productions required for this plan
"""
if not self.bom:
self.raise_user_error('cannot_create_productions_missing_bom',
self.rec_name)
prod = {
'product': self.product,
'bom': self.bom,
'uom': unit,
'quantity': quantity,
}
if hasattr(self, 'route'):
prod['route'] = self.route
if hasattr(self, 'process'):
prod['process'] = self.process
res = [
prod
]
res.extend(self._get_chained_productions(self.product, self.bom,
quantity, unit))
return res
def _get_chained_productions(self, product, bom, quantity, unit,
plan_boms=None):
"Returns base values for chained productions"
pool = Pool()
Input = pool.get('production.bom.input')
if plan_boms is None:
plan_boms = {}
for plan_bom in self.boms:
if plan_bom.bom:
plan_boms[plan_bom.product.id] = plan_bom
factor = bom.compute_factor(product, quantity, unit)
res = []
for input_ in bom.inputs:
input_product = input_.product
if input_product.id in plan_boms:
# Create production for current product
plan_bom = plan_boms[input_product.id]
prod = {
'product': plan_bom.product,
'bom': plan_bom.bom,
'uom': input_.uom,
'quantity': Input.compute_quantity(input_, factor),
}
res.append(prod)
# Search for more chained productions
res.extend(self._get_chained_productions(input_product,
plan_bom.bom, quantity, input_.uom, plan_boms))
return res
class ChangeLineQuantityStart:
__name__ = 'sale.change_line_quantity.start'

View File

@ -1,19 +1,5 @@
<tryton>
<data>
<!-- sale.line -->
<record model="ir.ui.view" id="sale_line_view_form">
<field name="model">sale.line</field>
<field name="type" eval="None"/>
<field name="inherit" ref="sale.sale_line_view_form"/>
<field name="name">sale_line_form</field>
</record>
<record model="ir.ui.view" id="sale_line_view_tree_sequence">
<field name="model">sale.line</field>
<field name="inherit" ref="sale.sale_line_view_tree_sequence"/>
<field name="name">sale_line_tree_sequence</field>
</record>
<!-- sale -->
<record model="ir.ui.view" id="sale_view_form">
<field name="model">sale.sale</field>

View File

@ -6,7 +6,7 @@ import re
import os
import ConfigParser
MODULE = 'sale_cost_plan'
MODULE = 'sale_supply_production'
PREFIX = 'nantic'
MODULE2PREFIX = {}

View File

@ -1,4 +1,4 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from .test_sale_cost_plan import suite
from .test_sale_supply_production import suite

View File

@ -28,7 +28,7 @@ Create database::
Install production Module::
>>> Module = Model.get('ir.module')
>>> modules = Module.find([('name', '=', 'sale_cost_plan')])
>>> modules = Module.find([('name', '=', 'sale_supply_production')])
>>> Module.install([x.id for x in modules], config.context)
>>> Wizard('ir.module.install_upgrade').execute('upgrade')

View File

@ -29,7 +29,7 @@ Install production Module::
>>> Module = Model.get('ir.module')
>>> modules = Module.find([
... ('name', 'in', ['sale_cost_plan', 'sale_change_quantity'])])
... ('name', 'in', ['sale_supply_production', 'sale_change_quantity'])])
>>> Module.install([x.id for x in modules], config.context)
>>> Wizard('ir.module.install_upgrade').execute('upgrade')

View File

@ -11,19 +11,19 @@ from trytond.tests.test_tryton import doctest_checker
class TestCase(ModuleTestCase):
'Test module'
module = 'sale_cost_plan'
module = 'sale_supply_production'
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCase))
suite.addTests(doctest.DocFileSuite(
'scenario_sale_cost_plan.rst',
'scenario_sale_supply_production.rst',
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
suite.addTests(doctest.DocFileSuite(
'scenario_sale_cost_plan_change_quantity.rst',
'scenario_sale_supply_production_change_quantity.rst',
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))

View File

@ -4,6 +4,7 @@ depends:
product_cost_plan_margin
production_origin
sale
sale_cost_plan
extras_depend:
sale_change_quantity
sale_discount

View File

@ -1,6 +0,0 @@
<data>
<xpath expr="/form/field[@name='uom']" position="after">
<label name="cost_plan"/>
<field name="cost_plan"/>
</xpath>
</data>

View File

@ -1,7 +0,0 @@
<data>
<xpath expr="/form/notebook/page/field[@name='product']"
position="after">
<label name="cost_plan"/>
<field name="cost_plan"/>
</xpath>
</data>

View File

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/tree/field[@name='product']" position="after">
<field name="cost_plan"/>
</xpath>
</data>