Add wizard to modify purchase's sale line quantity
This commit is contained in:
parent
11386c9735
commit
d7bf7e4dbc
|
@ -1,3 +1,5 @@
|
|||
* Add wizard to modify purchase's sale line quantity
|
||||
|
||||
Version 3.4.2 - 2015-04-04
|
||||
* Add compatibility with new module sale_change_quantity
|
||||
|
||||
|
|
|
@ -11,10 +11,12 @@ def register():
|
|||
Production,
|
||||
Plan,
|
||||
PlanBOM,
|
||||
ChangeQuantityStart,
|
||||
SaleLine,
|
||||
Sale,
|
||||
ChangeLineQuantityStart,
|
||||
module='sale_cost_plan', type_='model')
|
||||
Pool.register(
|
||||
ChangeQuantity,
|
||||
ChangeLineQuantity,
|
||||
module='sale_cost_plan', type_='wizard')
|
||||
|
|
|
@ -10,6 +10,22 @@ msgstr ""
|
|||
"No es pot crear cap producció perquè el pla de cost \"%s\" no té una LdM "
|
||||
"associada."
|
||||
|
||||
msgctxt "error:production.change_quantity:"
|
||||
msgid ""
|
||||
"The Production \"%s\" is not related to any sale.\n"
|
||||
"In this case, you can't use this wizard but you can modify the quantity directly in production's form."
|
||||
msgstr ""
|
||||
"La producció \"%s\" no està associada a cap venda.\n"
|
||||
"En aquest cas, no pot utilitzar aquest assistent però pot modificar la quantitat directament al formulari de la producció."
|
||||
|
||||
msgctxt "error:production.change_quantity:"
|
||||
msgid ""
|
||||
"You cannot modify the quantity of Production \"%s\" because it is not in "
|
||||
"state \"Draft\" or \"Waiting\"."
|
||||
msgstr ""
|
||||
"No pot modificar la quantitat de la producció \"%s\" perquè no es troba en "
|
||||
"l'estat \"Esborrany\" ni \"En espera\"."
|
||||
|
||||
msgctxt "error:sale.change_line_quantity:"
|
||||
msgid "Quantity already produced!"
|
||||
msgstr "Ja s'ha produit aquesta quantitat!"
|
||||
|
@ -30,6 +46,34 @@ msgctxt "field:production,cost_plan:"
|
|||
msgid "Cost Plan"
|
||||
msgstr "Pla de costos"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,current_quantity:"
|
||||
msgid "Current Quantity"
|
||||
msgstr "Quantitat actual"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,id:"
|
||||
msgid "ID"
|
||||
msgstr "Identificador"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,new_quantity:"
|
||||
msgid "New Quantity"
|
||||
msgstr "Nova quantitat"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,production:"
|
||||
msgid "Production"
|
||||
msgstr "Producció"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,sale_line:"
|
||||
msgid "Sale Line"
|
||||
msgstr "Línia de venta"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,unit_digits:"
|
||||
msgid "Unit Digits"
|
||||
msgstr "Dígits de la unitat"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,uom:"
|
||||
msgid "Uom"
|
||||
msgstr "UdM"
|
||||
|
||||
msgctxt "field:sale.line,cost_plan:"
|
||||
msgid "Cost Plan"
|
||||
msgstr "Pla de costos"
|
||||
|
@ -46,6 +90,35 @@ msgctxt "model:ir.action,name:act_production_form"
|
|||
msgid "Productions"
|
||||
msgstr "Produccions"
|
||||
|
||||
msgctxt "model:ir.action,name:wizard_production_change_quantity"
|
||||
msgid "Change Sale Quantity"
|
||||
msgstr "Modificar quantitat venda"
|
||||
|
||||
msgctxt "model:production.change_quantity.start,name:"
|
||||
msgid "Change Production Quantity - Start"
|
||||
msgstr "Modificar quantitat producció - Inici"
|
||||
|
||||
msgctxt "view:production.change_quantity.start:"
|
||||
msgid "Change Sale Quantity"
|
||||
msgstr "Modificar quantitat venda"
|
||||
|
||||
msgctxt "view:production.change_quantity.start:"
|
||||
msgid ""
|
||||
"It will change the quantity of the origin sale line which has been confirmed"
|
||||
" by the customer. The orinal one will be mantained in the Confirmed Quantity"
|
||||
" field."
|
||||
msgstr ""
|
||||
"Es modificarà la quantitat de la línia de venda d'origen la qual va ser "
|
||||
"confirmada pel client. L'original es mantindrà al camp Quantitat confirmada."
|
||||
|
||||
msgctxt "view:sale.sale:"
|
||||
msgid "Productions"
|
||||
msgstr "Produccions"
|
||||
|
||||
msgctxt "wizard_button:production.change_quantity,start,end:"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancel·la"
|
||||
|
||||
msgctxt "wizard_button:production.change_quantity,start,modify:"
|
||||
msgid "Modify"
|
||||
msgstr "Modifica"
|
||||
|
|
|
@ -10,6 +10,20 @@ msgstr ""
|
|||
"No se puede crear la producción porque el plan de costes \"%s\" no tiene LdM"
|
||||
" asociada."
|
||||
|
||||
msgctxt "error:production.change_quantity:"
|
||||
msgid ""
|
||||
"The Production \"%s\" is not related to any sale.\n"
|
||||
"In this case, you can't use this wizard but you can modify the quantity directly in production's form."
|
||||
msgstr "La producción \"%s\" no está asociada a ninguna venta."
|
||||
|
||||
msgctxt "error:production.change_quantity:"
|
||||
msgid ""
|
||||
"You cannot modify the quantity of Production \"%s\" because it is not in "
|
||||
"state \"Draft\" or \"Waiting\"."
|
||||
msgstr ""
|
||||
"No puede modificar la cantidad de la producción \"%s\" porque no se "
|
||||
"encuentra en los estados \"Borrador\" ni \"En espera\"."
|
||||
|
||||
msgctxt "error:sale.change_line_quantity:"
|
||||
msgid "Quantity already produced!"
|
||||
msgstr "¡Ya se ha producido esta cantidad!"
|
||||
|
@ -30,6 +44,34 @@ 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"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,id:"
|
||||
msgid "ID"
|
||||
msgstr "Identificador"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,new_quantity:"
|
||||
msgid "New Quantity"
|
||||
msgstr "Nueva cantidad"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,production:"
|
||||
msgid "Production"
|
||||
msgstr "Producción"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,sale_line:"
|
||||
msgid "Sale Line"
|
||||
msgstr "Línea de venta"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,unit_digits:"
|
||||
msgid "Unit Digits"
|
||||
msgstr "Dígitos unidad"
|
||||
|
||||
msgctxt "field:production.change_quantity.start,uom:"
|
||||
msgid "Uom"
|
||||
msgstr "UdM"
|
||||
|
||||
msgctxt "field:sale.line,cost_plan:"
|
||||
msgid "Cost Plan"
|
||||
msgstr "Plan de costes"
|
||||
|
@ -46,6 +88,36 @@ msgctxt "model:ir.action,name:act_production_form"
|
|||
msgid "Productions"
|
||||
msgstr "Producciones"
|
||||
|
||||
msgctxt "model:ir.action,name:wizard_production_change_quantity"
|
||||
msgid "Change Sale Quantity"
|
||||
msgstr "Modificar cantidad venta"
|
||||
|
||||
msgctxt "model:production.change_quantity.start,name:"
|
||||
msgid "Change Production Quantity - Start"
|
||||
msgstr "Modificar cantidad producción - Inicio"
|
||||
|
||||
msgctxt "view:production.change_quantity.start:"
|
||||
msgid "Change Sale Quantity"
|
||||
msgstr "Modificar cantidad venta"
|
||||
|
||||
msgctxt "view:production.change_quantity.start:"
|
||||
msgid ""
|
||||
"It will change the quantity of the origin sale line which has been confirmed"
|
||||
" by the customer. The orinal one will be mantained in the Confirmed Quantity"
|
||||
" field."
|
||||
msgstr ""
|
||||
"Se modificará la cantidad de la línea de venta de origen, la cual fue "
|
||||
"confirmada por el cliente. La original se mantendrá en el campo Cantidad "
|
||||
"confirmada."
|
||||
|
||||
msgctxt "view:sale.sale:"
|
||||
msgid "Productions"
|
||||
msgstr "Producciones"
|
||||
|
||||
msgctxt "wizard_button:production.change_quantity,start,end:"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancel·lar"
|
||||
|
||||
msgctxt "wizard_button:production.change_quantity,start,modify:"
|
||||
msgid "Modify"
|
||||
msgstr "Modificar"
|
||||
|
|
136
production.py
136
production.py
|
@ -1,42 +1,17 @@
|
|||
#The COPYRIGHT file at the top level of this repository contains the full
|
||||
#copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import Button, StateTransition, StateView, Wizard
|
||||
from .tools import prepare_vals
|
||||
|
||||
__all__ = ['Production', 'Plan', 'PlanBOM']
|
||||
__all__ = ['Production', 'Plan', 'PlanBOM',
|
||||
'ChangeQuantityStart', 'ChangeQuantity']
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
|
||||
def prepare_vals(values, to_write=False):
|
||||
if isinstance(values, dict):
|
||||
if set(values.keys()) <= set(['add', 'remove']):
|
||||
res = []
|
||||
if to_write:
|
||||
if 'add' in values.keys():
|
||||
res.append(('create',
|
||||
prepare_vals([v[1] for v in values['add']])))
|
||||
if 'remove' in values.keys():
|
||||
res.append(('delete', values['remove']))
|
||||
else:
|
||||
# to create
|
||||
if 'add' in values.keys():
|
||||
res = [x for _, x in values['add']]
|
||||
else:
|
||||
res = {}
|
||||
for key, value in values.iteritems():
|
||||
if 'rec_name' in key or key == 'id':
|
||||
continue
|
||||
value = prepare_vals(value)
|
||||
if value is not None:
|
||||
res[key] = value
|
||||
return res or None
|
||||
elif isinstance(values, list):
|
||||
return [prepare_vals(v) for v in values]
|
||||
return values
|
||||
|
||||
|
||||
class Production:
|
||||
__name__ = 'production'
|
||||
|
||||
|
@ -116,13 +91,13 @@ class Plan:
|
|||
for input_ in bom.inputs:
|
||||
input_product = input_.product
|
||||
if input_product.id in plan_boms:
|
||||
#Create production for current product
|
||||
# Create production for current product
|
||||
plan_bom = plan_boms[input_product.id]
|
||||
prod = plan_bom.get_production_data()
|
||||
prod['quantity'] = Input.compute_quantity(input_, factor)
|
||||
prod['uom'] = input_.uom
|
||||
res.append(prod)
|
||||
#Search for more chained productions
|
||||
# Search for more chained productions
|
||||
res.extend(self._get_chained_productions(input_product,
|
||||
plan_bom.bom, quantity, input_.uom))
|
||||
return res
|
||||
|
@ -170,7 +145,7 @@ class Plan:
|
|||
if Operation:
|
||||
production.operations = []
|
||||
changes = production.update_operations()
|
||||
for index, operation_vals in changes['operations']['add']:
|
||||
for _, operation_vals in changes['operations']['add']:
|
||||
operation_vals = prepare_vals(operation_vals)
|
||||
production.operations.append(Operation(**operation_vals))
|
||||
|
||||
|
@ -179,9 +154,9 @@ class Plan:
|
|||
production.inputs = []
|
||||
production.outputs = []
|
||||
changes = production.explode_bom()
|
||||
for index, input_vals in changes['inputs']['add']:
|
||||
for _, input_vals in changes['inputs']['add']:
|
||||
production.inputs.append(Move(**input_vals))
|
||||
for index, output_vals in changes['outputs']['add']:
|
||||
for _, output_vals in changes['outputs']['add']:
|
||||
production.outputs.append(Move(**output_vals))
|
||||
return production
|
||||
|
||||
|
@ -196,3 +171,90 @@ class PlanBOM:
|
|||
'product': self.product,
|
||||
'bom': self.bom,
|
||||
}
|
||||
|
||||
|
||||
class ChangeQuantityStart(ModelView):
|
||||
'Change Production Quantity - Start'
|
||||
__name__ = 'production.change_quantity.start'
|
||||
|
||||
production = fields.Many2One('production', 'Production', readonly=True)
|
||||
sale_line = fields.Many2One('sale.line', 'Sale Line', readonly=True)
|
||||
current_quantity = fields.Float('Current Quantity',
|
||||
digits=(16, Eval('unit_digits', 2)), readonly=True,
|
||||
depends=['unit_digits'])
|
||||
new_quantity = fields.Float('New Quantity',
|
||||
digits=(16, Eval('unit_digits', 2)), required=True,
|
||||
domain=[
|
||||
('new_quantity', '!=', Eval('current_quantity')),
|
||||
('new_quantity', '>', 0),
|
||||
],
|
||||
depends=['unit_digits', 'current_quantity'])
|
||||
uom = fields.Many2One('product.uom', 'Uom', readonly=True)
|
||||
unit_digits = fields.Integer('Unit Digits', readonly=True)
|
||||
|
||||
|
||||
class ChangeQuantity(Wizard):
|
||||
'Change Production Quantity'
|
||||
__name__ = 'production.change_quantity'
|
||||
|
||||
start = StateView('production.change_quantity.start',
|
||||
'sale_cost_plan.production_change_quantity_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Modify', 'modify', 'tryton-ok', default=True),
|
||||
])
|
||||
modify = StateTransition()
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(ChangeQuantity, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'invalid_production_state': (
|
||||
'You cannot modify the quantity of Production "%s" '
|
||||
'because it is not in state "Draft" or "Waiting".'),
|
||||
'production_no_related_to_sale': (
|
||||
'The Production "%s" is not related to any sale.\n'
|
||||
'In this case, you can\'t use this wizard but you can '
|
||||
'modify the quantity directly in production\'s form.'),
|
||||
})
|
||||
|
||||
def default_start(self, fields):
|
||||
pool = Pool()
|
||||
Production = pool.get('production')
|
||||
SaleLine = Pool().get('sale.line')
|
||||
|
||||
production = Production(Transaction().context['active_id'])
|
||||
if production.state not in ('draft', 'waiting'):
|
||||
self.raise_user_error('invalid_production_state',
|
||||
production.rec_name)
|
||||
if not isinstance(production.origin, SaleLine):
|
||||
self.raise_user_error('production_no_related_to_sale')
|
||||
return {
|
||||
'production': production.id,
|
||||
'sale_line': production.origin.id,
|
||||
'current_quantity': production.quantity,
|
||||
'uom': production.uom.id,
|
||||
'unit_digits': production.uom.digits,
|
||||
}
|
||||
|
||||
def transition_modify(self):
|
||||
pool = Pool()
|
||||
Uom = pool.get('product.uom')
|
||||
SaleChangeLineQuantity = pool.get('sale.change_line_quantity',
|
||||
type='wizard')
|
||||
|
||||
sale_line = self.start.sale_line
|
||||
sale_line_new_quantity = (sale_line.quantity
|
||||
+ Uom.compute_qty(
|
||||
self.start.uom,
|
||||
self.start.new_quantity - self.start.current_quantity,
|
||||
sale_line.unit))
|
||||
|
||||
sale_change_quantity = SaleChangeLineQuantity(self._session_id)
|
||||
sale_change_quantity.start.sale = sale_line.sale
|
||||
sale_change_quantity.start.line = sale_line
|
||||
sale_change_quantity.start.current_quantity = sale_line.quantity
|
||||
sale_change_quantity.start.new_quantity = sale_line_new_quantity
|
||||
sale_change_quantity.start.unit = sale_line.unit
|
||||
sale_change_quantity.start.unit_digits = sale_line.unit.digits
|
||||
sale_change_quantity.transition_modify()
|
||||
return 'end'
|
||||
|
|
|
@ -1,10 +1,36 @@
|
|||
<tryton>
|
||||
<data>
|
||||
<!-- production -->
|
||||
<record model="ir.ui.view" id="production_view_form">
|
||||
<field name="model">production</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit" ref="production.production_view_form"/>
|
||||
<field name="name">production_form</field>
|
||||
</record>
|
||||
|
||||
<!-- production.change_quantity -->
|
||||
<record model="ir.ui.view" id="production_change_quantity_start_view_form">
|
||||
<field name="model">production.change_quantity.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">production_change_quantity_start_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.wizard" id="wizard_production_change_quantity">
|
||||
<field name="name">Change Sale Quantity</field>
|
||||
<field name="wiz_name">production.change_quantity</field>
|
||||
<field name="model">production</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword"
|
||||
id="act_wizard_production_change_quantity_keyword">
|
||||
<field name="keyword">form_action</field>
|
||||
<field name="model">production,-1</field>
|
||||
<field name="action" ref="wizard_production_change_quantity"/>
|
||||
</record>
|
||||
<record model="ir.action-res.group"
|
||||
id="wizard_production_change_quantity-group_sale_change_line_quantity">
|
||||
<field name="action" ref="wizard_production_change_quantity"/>
|
||||
<field name="group"
|
||||
ref="sale_change_quantity.group_sale_change_line_quantity"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<form string="Change Sale Quantity" col="6">
|
||||
<image name="tryton-dialog-warning" xexpand="0" xfill="0"/>
|
||||
<label string="It will change the quantity of the origin sale line which has been confirmed by the customer. The orinal one will be mantained in the Confirmed Quantity field."
|
||||
id="advice" yalign="0.0" xalign="0.0" xexpand="1" colspan="5"/>
|
||||
<label name="sale_line"/>
|
||||
<field name="sale_line" colspan="5"/>
|
||||
<label name="current_quantity"/>
|
||||
<field name="current_quantity"/>
|
||||
<label name="new_quantity"/>
|
||||
<field name="new_quantity"/>
|
||||
<label name="uom"/>
|
||||
<field name="uom"/>
|
||||
</form>
|
Loading…
Reference in New Issue