First working version of service_line_qty_update_*

This commit is contained in:
Alexis de Lattre
2020-05-29 23:21:54 +02:00
parent 5c7985a15c
commit 28be3e4e6a
5 changed files with 29 additions and 18 deletions

View File

@@ -18,7 +18,7 @@ class ServiceQtyUpdate(models.TransientModel):
def run(self): def run(self):
self.ensure_one() self.ensure_one()
prec = self.env['decimal.precision'].precision_get('Product Unit of Measure') prec = self.env['decimal.precision'].precision_get('Product Unit of Measure')
for line in self: for line in self.line_ids:
if float_compare(line.post_delivered_qty, line.order_qty, precision_digits=prec) > 0: if float_compare(line.post_delivered_qty, line.order_qty, precision_digits=prec) > 0:
raise UserError(_( raise UserError(_(
"On line '%s', the total delivered qty (%s) is superior to the ordered qty (%s).") % (line.name, line.post_delivered_qty, line.order_qty)) "On line '%s', the total delivered qty (%s) is superior to the ordered qty (%s).") % (line.name, line.post_delivered_qty, line.order_qty))
@@ -38,15 +38,15 @@ class ServiceQtyUpdateLine(models.TransientModel):
parent_id = fields.Many2one( parent_id = fields.Many2one(
'service.qty.update', string='Wizard', ondelete='cascade') 'service.qty.update', string='Wizard', ondelete='cascade')
product_id = fields.Many2one('product.product', string='Product', readonly=True) product_id = fields.Many2one('product.product', string='Product', readonly=True)
name = fields.Char(string='Description', readonly=True) name = fields.Char()
name_readonly = fields.Char(related='name', string='Description')
order_qty = fields.Float( order_qty = fields.Float(
string='Order Qty', string='Order Qty',
digits=dp.get_precision('Product Unit of Measure'), digits=dp.get_precision('Product Unit of Measure'))
readonly=True) order_qty_readonly = fields.Float(related='order_qty', string='Product Unit of Measure')
pre_delivered_qty = fields.Float( pre_delivered_qty = fields.Float(
string='Current Delivered Qty', digits=dp.get_precision('Product Unit of Measure'))
digits=dp.get_precision('Product Unit of Measure'), pre_delivered_qty_readonly = fields.Float(related='pre_delivered_qty', string='Current Delivered Qty')
readonly=True)
added_delivered_qty = fields.Float( added_delivered_qty = fields.Float(
string='Added Delivered Qty', string='Added Delivered Qty',
digits=dp.get_precision('Product Unit of Measure')) digits=dp.get_precision('Product Unit of Measure'))

View File

@@ -13,12 +13,15 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form> <form>
<group name="main"> <group name="main">
<field name="line_ids" editable="bottom" nolabel="1" options="{'no_create': True}"> <field name="line_ids" nolabel="1">
<tree> <tree editable="bottom">
<field name="product_id"/> <field name="product_id"/>
<field name="name"/> <field name="name" invisible="0"/>
<field name="order_qty"/> <field name="name_readonly"/>
<field name="pre_delivered_qty"/> <field name="order_qty" invisible="1"/>
<field name="order_qty_readonly"/>
<field name="pre_delivered_qty" invisible="1"/>
<field name="pre_delivered_qty_readonly"/>
<field name="added_delivered_qty"/> <field name="added_delivered_qty"/>
<field name="post_delivered_qty"/> <field name="post_delivered_qty"/>
<field name="uom_id" groups="uom.group_uom"/> <field name="uom_id" groups="uom.group_uom"/>

View File

@@ -10,7 +10,11 @@
'summary': 'Update delivery qty on service lines - Purchase module', 'summary': 'Update delivery qty on service lines - Purchase module',
'author': 'Akretion', 'author': 'Akretion',
'website': 'http://www.akretion.com', 'website': 'http://www.akretion.com',
'depends': ['purchase'], 'depends': [
'purchase',
'service_line_qty_update_base',
'purchase_reception_status',
],
'data': [ 'data': [
'views/purchase_order.xml', 'views/purchase_order.xml',
], ],

View File

@@ -14,7 +14,7 @@
<field name="inherit_id" ref="purchase.purchase_order_form"/> <field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<button name="action_view_invoice" position="after"> <button name="action_view_invoice" position="after">
<button name="%(service_line_qty_update_base.service_qty_update_action)d" type="action" string="Update Service Qty" attrs="{'invisible': ['|', ('state', 'not in', ('purchase', 'done')), ('has_service', '=', False)]}"/> <button name="%(service_line_qty_update_base.service_qty_update_action)d" type="action" string="Update Service Qty" attrs="{'invisible': ['|', '|', ('state', 'not in', ('purchase', 'done')), ('has_service', '=', False), ('reception_status', '=', 'received')]}" groups="purchase.group_purchase_user"/>
<field name="has_service" invisible="1"/> <field name="has_service" invisible="1"/>
</button> </button>
<xpath expr="//field[@name='order_line']/tree/field[@name='qty_received']" position="attributes"> <xpath expr="//field[@name='order_line']/tree/field[@name='qty_received']" position="attributes">

View File

@@ -24,8 +24,11 @@ class ServiceQtyUpdate(models.TransientModel):
'purchase_line_id': l.id, 'purchase_line_id': l.id,
'product_id': l.product_id.id, 'product_id': l.product_id.id,
'name': l.name, 'name': l.name,
'name_readonly': l.name,
'order_qty': l.product_qty, 'order_qty': l.product_qty,
'order_qty_readonly': l.product_qty,
'pre_delivered_qty': l.qty_received, 'pre_delivered_qty': l.qty_received,
'pre_delivered_qty_readonly': l.qty_received,
'uom_id': l.product_uom.id, 'uom_id': l.product_uom.id,
})) }))
if lines: if lines:
@@ -44,14 +47,15 @@ class ServiceQtyUpdateLine(models.TransientModel):
def process_line(self): def process_line(self):
po_line = self.purchase_line_id po_line = self.purchase_line_id
if po_line: if po_line:
po_line.write({'qty_received': self.post_delivered_qty}) new_qty = po_line.qty_received + self.added_delivered_qty
po_line.write({'qty_received': new_qty})
body = """ body = """
<p>Received qty updated on service line <em>%s</em>: <p>Received qty updated on service line <b>%s</b>:
<ul> <ul>
<li>Added received qty: %s</li> <li>Added received qty: <b>%s</b></li>
<li>Total received qty: %s</li> <li>Total received qty: %s</li>
</ul></p> </ul></p>
""" % (self.added_delivered_qty, self.post_delivered_qty) """ % (self.name, self.added_delivered_qty, new_qty)
if self.comment: if self.comment:
body += '<p>Comment: %s</p>' % self.comment body += '<p>Comment: %s</p>' % self.comment
po_line.order_id.message_post(body=body) po_line.order_id.message_post(body=body)