[FIX] purchase: `related_usage` must be readonly

The `related_usage` field of `purchase.order`
is a related field to the location `usage` field,
which is defined in order to display/hide
some other field in the PO according to the location usage

This is purely a technical field, which is set only
to change the form view according to the location
usage.

This is not expected to change the location usage
through this field, this field must therefore
be set to readonly.

A change on the location usage could happen because
of the `onchange_picking_type_id`:
If the user changed the picking type, and then the location,
the usage returned by the `onchange_picking_type_id` was
applied on the location, and this must not have happened.

In addition, since `related_usage` is a related to the location
usage, it should be changed as well when the location is changed.
(in the new api, this is no longer required, the related field
is updated automatically).

This revision therefore adds an onchange on the location as well,
to handle this.

opw-676428
This commit is contained in:
Denis Ledoux 2016-06-16 11:24:13 +02:00
parent 606eab8ef8
commit ae74ebb5ce
2 changed files with 9 additions and 2 deletions

View File

@ -316,7 +316,7 @@ class purchase_order(osv.osv):
'picking_type_id': fields.many2one('stock.picking.type', 'Deliver To', help="This will determine picking type of incoming shipment", required=True,
states={'confirmed': [('readonly', True)], 'approved': [('readonly', True)], 'done': [('readonly', True)]}),
'related_location_id': fields.related('picking_type_id', 'default_location_dest_id', type='many2one', relation='stock.location', string="Related location", store=True),
'related_usage': fields.related('location_id', 'usage', type='char'),
'related_usage': fields.related('location_id', 'usage', type='char', readonly=True),
'shipment_count': fields.function(_count_all, type='integer', string='Incoming Shipments', multi=True),
'invoice_count': fields.function(_count_all, type='integer', string='Invoices', multi=True)
}
@ -421,6 +421,13 @@ class purchase_order(osv.osv):
value.update({'related_location_id': picktype.default_location_dest_id.id})
return {'value': value}
def onchange_location_id(self, cr, uid, ids, location_id, context=None):
value = {'related_usage': False}
if location_id:
value['related_usage'] = self.pool['stock.location'].browse(cr, uid, location_id, context=context).usage
return {'value': value}
def onchange_partner_id(self, cr, uid, ids, partner_id, context=None):
partner = self.pool.get('res.partner')
if not partner_id:

View File

@ -274,7 +274,7 @@
<group>
<group>
<field name="minimum_planned_date"/>
<field name="location_id" groups="stock.group_locations"/>
<field name="location_id" groups="stock.group_locations" on_change="onchange_location_id(location_id, context)"/>
<field name="shipped" groups="base.group_no_one"/>
</group>
<group>