I am try to override create method in sale order to make purchase order with current data in sale order and my code did not work Iam try this:
@api.multi
def creat(self): # for order in self: # order.state = 'sale' # order.confirmation_date = fields.Datetime.now() # if self.env.context.get('send_email'): # self.force_quotation_send() # order.order_line._action_procurement_create() # if self.env['ir.values'].get_default('sale.config.settings', 'auto_done_setting'): # self.action_done()
self.env['purchase.order'].create({'partner_id': partner_id.id,
'location_id':location_id.id,
'pricelist_id': pricelist_id.id,
'order_line': [(0, 0, {'product_id': product_id.id,
'name': name.id,
'date_planned': date_planned.id,
'price_unit': price_unit.id})]})
return True
You have to use api.model for create method as there is no id for the record when creating a new record.
here is a sample code
@api.model
def create(self, vals):
res = super(ClassName, self).create(vals)
# Your code here
# vals will contain dictionary of all variables.
return res
Also You don't have to change code for creating purchase order from sales. You just have to set routes(Buy in this case) for the product and product's vendor.