[REF] purchase_requisition: vendor mandatory in blanket order

The vendor is now a mandatory field in the blanket order form
because it's directly linked to purchase orders. So Odoo needs
to know to which supplier the PO is addressed.
This commit is contained in:
William Henrotin
2018-02-01 15:11:14 +01:00
committed by Pierre Masereel
parent 02ec09cb1c
commit d8d925d366
2 changed files with 19 additions and 1 deletions
@@ -66,6 +66,23 @@ class PurchaseRequisition(models.Model):
copy=False, default='draft')
account_analytic_id = fields.Many2one('account.analytic.account', 'Analytic Account')
picking_type_id = fields.Many2one('stock.picking.type', 'Operation Type', required=True, default=_get_picking_in)
is_quantity_copy = fields.Selection(related='type_id.quantity_copy', readonly=True)
@api.onchange('vendor_id')
def _onchange_vendor(self):
requisitions = self.env['purchase.requisition'].search([
('vendor_id', '=', self.vendor_id.id),
('state', '=', 'ongoing'),
('type_id.quantity_copy', '=', 'none'),
])
if any(requisitions):
title = _("Warning for %s") % self.vendor_id.name
message = _("%s has already an ongoing blanket order") % self.vendor_id.name
warning = {
'title': title,
'message': message
}
return {'warning': warning}
@api.multi
@api.depends('purchase_ids')
@@ -149,9 +149,10 @@
</div>
<group>
<group>
<field name="is_quantity_copy" invisible='1'/>
<field name="user_id" attrs="{'readonly': [('state','not in',('draft','in_progress','open'))]}"/>
<field name="type_id" attrs="{'readonly': [('state','not in',('draft','in_progress','open'))]}" widget="selection"/>
<field name="vendor_id" context="{'search_default_supplier':1, 'default_supplier':1, 'default_customer':0}" domain="[('supplier','=',True)]"/>
<field name="vendor_id" context="{'search_default_supplier':1, 'default_supplier':1, 'default_customer':0}" domain="[('supplier','=',True)]" attrs="{'required': [('is_quantity_copy', '=', 'none')]}"/>
<field name="account_analytic_id" colspan="2" groups="analytic.group_analytic_accounting" attrs="{'readonly': [('state','not in',('draft'))]}"/>
</group>
<group>