Hello everyone so i tried to extend python function but its not working. the function i want to extend is from model 'sale.order' and the function is like this
def _prepare_purchase_order_data(self, company, company_partner):
""" Generate purchase order values, from the SO (self)
:param company_partner : the partner representing the company of the SO
:rtype company_partner : res.partner record
:param company : the company in which the PO line will be created
:rtype company : res.company record
"""
self.ensure_one()
# find location and warehouse, pick warehouse from company object
warehouse = company.warehouse_id and company.warehouse_id.company_id.id == company.id and company.warehouse_id or False
if not warehouse:
raise UserError(_('Configure correct warehouse for company(%s) from Menu: Settings/Users/Companies', company.name))
picking_type_id = self.env['stock.picking.type'].search([
('code', '=', 'incoming'), ('warehouse_id', '=', warehouse.id)
], limit=1)
if not picking_type_id:
intercompany_uid = company.intercompany_user_id.id
picking_type_id = self.env['purchase.order'].with_user(intercompany_uid)._default_picking_type()
return {
'name': self.env['ir.sequence'].sudo().next_by_code('purchase.order'),
'origin': self.name,
'partner_id': company_partner.id,
'picking_type_id': picking_type_id.id,
'date_order': self.date_order,
'company_id': company.id,
'fiscal_position_id': company_partner.property_account_position_id.id,
'payment_term_id': company_partner.property_supplier_payment_term_id.id,
'auto_generated': True,
'auto_sale_order_id': self.id,
'partner_ref': self.name,
'currency_id': self.currency_id.id,
'order_line': [],
}
i want to extend using below code, just want to add another line to export that is custom_internal
class SaleOrder(models.Model):
_inherit = 'sale.order'
custom_internal = fields.Boolean(string='Internal', default=False)
def _prepare_purchase_order_data(self, company, company_partner):
# Call the original function to get the dictionary
print('debug1')
res = super(SaleOrder, self)._prepare_purchase_order_data(company, company_partner)
print('debug2')
# Update internal field
res.update({'custom_internal': self.custom_internal})
print('debug3')
return res
When odoo default function try to call the function above, my code didn't run and get ignored (the 3 debug print didnt come out at all). iam really confused now and would welcome any help, thanks!