Retrieve analytic account from purchase request and set it on purchase requisition line
This commit is contained in:
parent
599c0955aa
commit
9556570ea4
|
|
@ -165,15 +165,16 @@ class PurchaseRequest(models.Model):
|
|||
raise ValidationError(_("Choose A Department For this Employee!"))
|
||||
line_ids = []
|
||||
for line in self.line_ids.filtered(lambda line: line.qty_purchased > 0):
|
||||
account_analytic_id = self.account_analytic_id.id if self.use_analytic and self.account_analytic_id else line.account_id.id
|
||||
line_ids.append((0, 6, {
|
||||
'product_id': line.product_id.id,
|
||||
'department_id': line.request_id.sudo().department_id.id or False,
|
||||
'product_qty': line.qty_purchased,
|
||||
'name': line.product_id.name,
|
||||
'account_analytic_id': line.account_id.id,
|
||||
'account_analytic_id': account_analytic_id,
|
||||
'product_uom_id': line.uom_id.id
|
||||
}))
|
||||
requisition_id = self.env['purchase.requisition'].sudo().create({
|
||||
requisition_vals = {
|
||||
'category_ids': self.product_category_ids.ids,
|
||||
'type_id_test': self.type_id.id,
|
||||
'department_id': self.sudo().employee_id.department_id.id,
|
||||
|
|
@ -184,8 +185,10 @@ class PurchaseRequest(models.Model):
|
|||
'line_ids': line_ids,
|
||||
'res_id': self.id,
|
||||
'res_model': "purchase.request",
|
||||
|
||||
})
|
||||
}
|
||||
if self.use_analytic and self.account_analytic_id:
|
||||
requisition_vals['purchase_cost'] = 'product_line'
|
||||
requisition_id = self.env['purchase.requisition'].sudo().create(requisition_vals)
|
||||
self.write({'purchase_create': True, 'state': 'employee'})
|
||||
|
||||
return {
|
||||
|
|
@ -201,12 +204,13 @@ class PurchaseRequest(models.Model):
|
|||
raise ValidationError(_("Please Insert a Vendor"))
|
||||
line_ids = []
|
||||
for line in self.line_ids.filtered(lambda line: line.qty_purchased > 0):
|
||||
account_analytic_id = self.account_analytic_id.id if self.use_analytic and self.account_analytic_id else line.account_id.id
|
||||
line_ids.append((0, 6, {
|
||||
'product_id': line.product_id.id,
|
||||
'product_qty': line.qty_purchased,
|
||||
'name': line.description or line.product_id.name,
|
||||
'department_name': self.sudo().employee_id.department_id.id,
|
||||
'account_analytic_id': line.account_id.id,
|
||||
'account_analytic_id': account_analytic_id,
|
||||
'date_planned': datetime.today(),
|
||||
'price_unit': 0,
|
||||
}))
|
||||
|
|
@ -230,7 +234,8 @@ class PurchaseRequest(models.Model):
|
|||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'purchase.order',
|
||||
'view_mode': 'form',
|
||||
'res_id': purchase_order.id}
|
||||
'res_id': purchase_order.id,
|
||||
}
|
||||
|
||||
def action_confirm_picking(self):
|
||||
if not self.line_ids:
|
||||
|
|
|
|||
Loading…
Reference in New Issue