mirror of
https://bitbucket.org/presik/trytonpsk-stock_co.git
synced 2023-12-14 05:43:05 +01:00
add option to change udm in products
This commit is contained in:
parent
be5ee13825
commit
23cd1e9a07
|
@ -29,6 +29,7 @@ def register():
|
|||
inventory.Inventory,
|
||||
inventory.CreateInventoriesStart,
|
||||
stock.WarehouseKardexStockStart,
|
||||
product.ChangeUdmProductStart,
|
||||
module='stock_co', type_='model')
|
||||
Pool.register(
|
||||
shipment.ShipmentDetailed,
|
||||
|
@ -45,6 +46,7 @@ def register():
|
|||
shipment.ShipmentInForceDraft,
|
||||
shipment.ShipmentInReturnForceDraft,
|
||||
shipment.ShipmentInternalLoadStock,
|
||||
product.ChangeUdmProduct,
|
||||
module='stock_co', type_='wizard')
|
||||
Pool.register(
|
||||
stock.MoveByProduct,
|
||||
|
|
69
product.py
69
product.py
|
@ -128,6 +128,75 @@ class AverageCost(ModelSQL, ModelView):
|
|||
cls._order.insert(0, ('effective_date', 'DESC'))
|
||||
|
||||
|
||||
class ChangeUdmProductStart(ModelView):
|
||||
'Change Udm Product Start'
|
||||
|
||||
__name__ = 'stock_co.change_udm_product.start'
|
||||
|
||||
udm = fields.Many2One('product.uom', "UOM", required=True,
|
||||
help="If change the uom in product, this update the uom in sales, purchases \b \
|
||||
invoices and moves stock")
|
||||
|
||||
class ChangeUdmProduct(Wizard):
|
||||
'Change Udm Product'
|
||||
|
||||
__name__ = 'stock_co.change_udm_product'
|
||||
|
||||
start = StateView('stock_co.change_udm_product.start',
|
||||
'stock_co.change_udm_product_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Accept', 'accept', 'tryton-ok', default=True),
|
||||
])
|
||||
accept = StateTransition()
|
||||
|
||||
def transition_accept(self):
|
||||
pool = Pool()
|
||||
cursor = Transaction().connection.cursor()
|
||||
Template = pool.get('product.template')
|
||||
Sale = pool.get('sale.line')
|
||||
Purchase = pool.get('purchase.line')
|
||||
Invoice = pool.get('account.invoice.line')
|
||||
Move = pool.get('stock.move')
|
||||
|
||||
sale = Sale.__table__()
|
||||
purchase = Purchase.__table__()
|
||||
invoice = Invoice.__table__()
|
||||
move = Move.__table__()
|
||||
template = Template.__table__()
|
||||
|
||||
product_template = Template(Transaction().context.get('active_id'))
|
||||
product_id = product_template.products[0].id
|
||||
uom_update = self.start.udm.id
|
||||
sale_uom = product_template.sale_uom.id
|
||||
purchase_uom = product_template.purchase_uom.id
|
||||
default_uom = product_template.default_uom.id
|
||||
|
||||
cursor.execute(*sale.update(
|
||||
[sale.unit], [uom_update],
|
||||
where=(sale.unit == sale_uom) & (sale.product == product_id)))
|
||||
cursor.execute(*purchase.update(
|
||||
[purchase.unit], [uom_update],
|
||||
where=(purchase.unit == purchase_uom) & (purchase.product == product_id)))
|
||||
cursor.execute(*invoice.update(
|
||||
[invoice.unit], [uom_update],
|
||||
where=(invoice.unit == purchase_uom)
|
||||
& (invoice.invoice_type == 'in')
|
||||
& (invoice.product == product_id)))
|
||||
cursor.execute(*invoice.update(
|
||||
[invoice.unit], [uom_update],
|
||||
where=(invoice.unit == sale_uom)
|
||||
& (invoice.invoice_type == 'out')
|
||||
& (invoice.product == product_id)))
|
||||
cursor.execute(*move.update(
|
||||
[move.uom], [uom_update],
|
||||
where=(move.uom == default_uom) & (move.product == product_id)))
|
||||
cursor.execute(*template.update(
|
||||
[template.default_uom, template.purchase_uom, template.sale_uom],
|
||||
[uom_update, uom_update, uom_update],
|
||||
where=(template.id == product_template.id)))
|
||||
|
||||
return 'end'
|
||||
|
||||
# class UpdateAverageCosts(Wizard):
|
||||
# 'Update Average Costs'
|
||||
# __name__ = 'stock_co.update_average_costs'
|
||||
|
|
16
product.xml
16
product.xml
|
@ -21,6 +21,22 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="inherit" ref="product.template_view_form"/>
|
||||
<field name="name">template_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="change_udm_product_view_form">
|
||||
<field name="model">stock_co.change_udm_product.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">change_udm_product_form</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="wizard_change_udm_product">
|
||||
<field name="name">Change UDM product</field>
|
||||
<field name="wiz_name">stock_co.change_udm_product</field>
|
||||
<field name="model">product.template</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="change_udm_product_keyword">
|
||||
<field name="keyword">form_action</field>
|
||||
<field name="model">product.template,-1</field>
|
||||
<field name="action" ref="wizard_change_udm_product"/>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
7
view/change_udm_product_form.xml
Normal file
7
view/change_udm_product_form.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?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. -->
|
||||
<form>
|
||||
<label name="udm"/>
|
||||
<field name="udm"/>
|
||||
</form>
|
Loading…
Reference in a new issue