Skip to Content
Menu
This question has been flagged
2 Replies
6965 Views

I've installed a custom module from Odoo store which automatically creates a credit note for returned products but this module gets the price from the product form which may not include the price on orders.

I need to change the value of price on each line to be calculated from the order line even if it is on sale or purchased.

This is the create method:

    @api.multi   
    def create_refund_invoice(self):
inv_obj = self.env['account.invoice']
for pick in self.filtered(lambda x:x.return_type):
type = 'in_refund' if pick.return_type == 'purchase' else 'out_refund'
inv_lines = {'type':type, 'partner_id':pick.partner_id.id, 'invoice_line_ids':[]}
account = pick.return_type == 'sale' and pick.partner_id.property_account_receivable_id.id or pick.partner_id.property_account_payable_id.id
inv_lines['account_id'] = account
inv_lines['origin'] = pick.name
inv_lines['name'] = pick.origin
for line in pick.move_lines:
name = line.product_id.partner_ref
pricelist_id = pick.partner_id.property_product_pricelist
price = pricelist_id.get_product_price(line.product_id, 1, pick.partner_id) if pricelist_id else line.product_id.lst_price
# price = pricelist_id.get_product_price(line.product_id, 1, pick.partner_id) if pricelist_id else line.product_id.lst_price
# price = line.env['purchase.order'].search([('name','=',line.group_id)]).order_line.price_unit
# price = line.move_lines.sale_line_id.price_unit

inv_lines['invoice_line_ids'] += [(0, None, {'product_id':line.product_id.id,
'name':name,
'quantity':line.quantity_done,
'price_unit': price,
'account_id':line.product_id.product_tmpl_id.get_product_accounts()['income'].id})]
if inv_lines['invoice_line_ids']:
inv_id = inv_obj.create(inv_lines)
pick.invoice_id = inv_id.id

What should I do ? I tried to set the


          price = line.env['purchase.order'].search([('name','=',line.group_id)]).order_line.price_unit

but it makes the price = 0

Any help will be appreciated.

Avatar
Discard
Best Answer

@Pinakin

can I get the cheapest price for a product quoted  by different vendors using lambda or any other option and store somewhere saying vendor x was the cheapest

Avatar
Discard
Best Answer

You may try something like below,

purchase_order = self.env['purchase.order'].search([('name','=',pick.group_id.name)], limit=1)

if purchase_order:
price_unit = purchase_order.order_line.filtered(lambda x: x.product_id == line.product_id).price_unit​

Avatar
Discard
Related Posts Replies Views Activity
1
Feb 21
2071
1
Aug 24
301
2
Jul 18
1903
2
Oct 17
4646
2
Jun 24
1968