[IMP] purchase: edit received quantity on purchase_line when type service

When we purchase products of type services,the received quantity is
always set to the ordered quantity.

We want to be able to manually enter a received quantity on service
products to have a better trace of what have been received or not.

We show the picking stat button olnly if there are picking

We show the columns qty_received, qty_invoiced and invoice_status
depending on the parent state, and not depending on the context passed
in the menu item.
This commit is contained in:
Pierre Masereel
2017-11-08 15:28:07 +01:00
parent 0a5b2ea831
commit 2d3e6d7383
4 changed files with 34 additions and 32 deletions
+14 -20
View File
@@ -550,25 +550,6 @@ class PurchaseOrderLine(models.Model):
qty -= inv_line.uom_id._compute_quantity(inv_line.quantity, line.product_uom)
line.qty_invoiced = qty
@api.depends('order_id.state', 'move_ids.state', 'move_ids.product_uom_qty')
def _compute_qty_received(self):
for line in self:
if line.order_id.state not in ['purchase', 'done']:
line.qty_received = 0.0
continue
if line.product_id.type not in ['consu', 'product']:
line.qty_received = line.product_qty
continue
total = 0.0
for move in line.move_ids:
if move.state == 'done':
if move.location_dest_id.usage == "supplier":
if move.to_refund:
total -= move.product_uom._compute_quantity(move.product_uom_qty, line.product_uom)
else:
total += move.product_uom._compute_quantity(move.product_uom_qty, line.product_uom)
line.qty_received = total
@api.model
def create(self, values):
line = super(PurchaseOrderLine, self).create(values)
@@ -606,6 +587,7 @@ class PurchaseOrderLine(models.Model):
product_image = fields.Binary(
'Product Image', related="product_id.image",
help="Non-stored related field to allow portal user to see the image of the product he has ordered")
product_type = fields.Selection(related='product_id.type')
move_ids = fields.One2many('stock.move', 'purchase_line_id', string='Reservation', readonly=True, ondelete='set null', copy=False)
price_unit = fields.Float(string='Unit Price', required=True, digits=dp.get_precision('Product Price'))
@@ -623,7 +605,7 @@ class PurchaseOrderLine(models.Model):
# Replace by invoiced Qty
qty_invoiced = fields.Float(compute='_compute_qty_invoiced', string="Billed Qty", digits=dp.get_precision('Product Unit of Measure'), store=True)
qty_received = fields.Float(compute='_compute_qty_received', string="Received Qty", digits=dp.get_precision('Product Unit of Measure'), store=True)
qty_received = fields.Float(string="Received Qty", digits=dp.get_precision('Product Unit of Measure'))
partner_id = fields.Many2one('res.partner', related='order_id.partner_id', string='Partner', readonly=True, store=True)
currency_id = fields.Many2one(related='order_id.currency_id', store=True, string='Currency', readonly=True)
@@ -632,6 +614,18 @@ class PurchaseOrderLine(models.Model):
orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', 'Orderpoint')
move_dest_ids = fields.One2many('stock.move', 'created_purchase_line_id', 'Downstream Moves')
def _update_received_qty(self):
for line in self:
total = 0.0
for move in line.move_ids:
if move.state == 'done':
if move.location_dest_id.usage == "supplier":
if move.to_refund:
total -= move.product_uom._compute_quantity(move.product_uom_qty, line.product_uom)
else:
total += move.product_uom._compute_quantity(move.product_uom_qty, line.product_uom)
line.qty_received = total
@api.multi
def _create_or_update_picking(self):
for line in self:
+12
View File
@@ -71,6 +71,18 @@ class StockMove(models.Model):
vals['purchase_line_id'] = self.purchase_line_id.id
return vals
def _action_done(self):
res = super(StockMove, self)._action_done()
self.mapped('purchase_line_id').sudo()._update_received_qty()
return res
def write(self, vals):
res = super(StockMove, self).write(vals)
if 'product_uom_qty' in vals:
self.filtered(lambda m: m.state == 'done' and m.purchase_line_id).mapped(
'purchase_line_id').sudo()._update_received_qty()
return res
class StockWarehouse(models.Model):
_inherit = 'stock.warehouse'
+6 -8
View File
@@ -172,7 +172,7 @@
<button type="object"
name="action_view_picking"
class="oe_stat_button"
icon="fa-truck" attrs="{'invisible':[('state', 'in', ('draft','sent','to approve')),('picking_ids','=',[])]}">
icon="fa-truck" attrs="{'invisible':[('picking_ids','=',[])]}">
<field name="picking_count" widget="statinfo" string="Shipment" help="Incoming Shipments"/>
<field name="picking_ids" invisible="1"/>
</button>
@@ -209,6 +209,7 @@
<tree string="Purchase Order Lines" editable="bottom">
<field name="currency_id" invisible="1"/>
<field name="state" invisible="1"/>
<field name="product_type" invisible="1"/>
<field name="sequence" widget="handle"/>
<field name="product_id" attrs="{'readonly': [('state', 'in', ('purchase', 'to approve','done', 'cancel'))]}" context="{'partner_id':parent.partner_id, 'quantity':product_qty,'uom':product_uom, 'company_id': parent.company_id}"/>
<field name="name"/>
@@ -217,8 +218,8 @@
<field name="account_analytic_id" context="{'default_partner_id':parent.partner_id}" groups="purchase.group_analytic_accounting"/>
<field name="analytic_tag_ids" groups="purchase.group_analytic_accounting" widget="many2many_tags" options="{'color_field': 'color'}"/>
<field name="product_qty"/>
<field name="qty_received" invisible="not context.get('show_purchase', True)"/>
<field name="qty_invoiced" invisible="not context.get('show_purchase', True)"/>
<field name="qty_received" attrs="{'column_invisible': [('parent.state', 'not in', ('purchase', 'done'))], 'readonly': [('product_type', 'in', ('consu', 'product'))]}"/>
<field name="qty_invoiced" attrs="{'column_invisible': [('parent.state', 'not in', ('purchase', 'done'))]}"/>
<field name="product_uom" groups="product.group_uom" attrs="{'readonly': [('state', 'in', ('purchase', 'done', 'cancel'))]}"/>
<field name="price_unit"/>
<field name="taxes_id" widget="many2many_tags" domain="[('type_tax_use','=','purchase')]" context="{'default_type_tax_use': 'purchase'}" options="{'no_create': True}"/>
@@ -398,7 +399,7 @@
<field name="amount_total" sum="Total amount" widget="monetary"/>
<field name="currency_id" invisible="1"/>
<field name="state"/>
<field name="invoice_status" invisible="not context.get('show_purchase', True)"/>
<field name="invoice_status" attrs="{'column_invisible': [('parent.state', 'not in', ('purchase', 'done'))]}"/>
</tree>
</field>
</record>
@@ -415,8 +416,6 @@
<field name="name">Requests for Quotation</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order</field>
<field name="context">{'search_default_todo':1, 'show_purchase': False}</field>
<field name="domain">[('state','in',('draft','sent','bid','cancel', 'confirmed'))]</field>
<field name="view_mode">tree,kanban,form,pivot,graph,calendar</field>
<field name="search_view_id" ref="view_purchase_order_filter"/>
<field name="help" type="html">
@@ -441,8 +440,7 @@
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order</field>
<field name="view_mode">tree,kanban,form,pivot,graph,calendar</field>
<field name="context">{'search_default_todo':1, 'show_purchase': True}</field>
<field name="domain">[('state','not in',('draft','sent','bid', 'confirmed'))]</field>
<field name="domain">[('state','in',('purchase', 'done'))]</field>
<field name="search_view_id" ref="view_purchase_order_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
+2 -4
View File
@@ -8,10 +8,8 @@ from odoo.tools import float_compare
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
qty_received = fields.Float(compute='_compute_qty_received', string="Received Qty", store=True)
def _compute_qty_received(self):
super(PurchaseOrderLine, self)._compute_qty_received()
def _update_received_qty(self):
super(PurchaseOrderLine, self)._update_received_qty()
for line in self.filtered(lambda x: x.move_ids and x.product_id.id not in x.move_ids.mapped('product_id').ids):
bom = self.env['mrp.bom']._bom_find(product=line.product_id, company_id=line.company_id.id)
if bom and bom.type == 'phantom':