Skip to Content
Menu
This question has been flagged
1 Reply
1208 Views

Hello,

I am working on Odoo 11 and I am trying to update the cost of items in the inventory module when I click on the validate button of a supplier invoice (Purchase module). The cost of the items shall take the cost indicated in the invoice.


I created the following method:


from odoo import fields, models, api

class ProductCost(models.Model):
    _inherit = 'account.invoice'
    @api.multi()
    def _get_last_price(self):
        for record in self.product_id:
            record.write({'standard_price': self.price_unit})
        return super(ProductCost, self).action_invoice_open()

But it doesn't work, if anyone can help me that would be great!


Thanks

Avatar
Discard
Author

It works !! thank you very much !

Best Answer

Use the below code:

class AccountInvoice(models.Model):
    _inherit = 'account.invoice'

    @api.multi()
    def action_invoice_open(self):
        res = super(AccountInvoice, self).action_invoice_open()
        for inv in self:
            for inv_line in inv.invoice_line_ids:
                product = inv_line.product_id
                if product:
                    product.write({'standard_price': inv_line.price_unit})
        return res
        
Avatar
Discard
Related Posts Replies Views Activity
2
Jul 24
939
1
Jun 24
3560
1
Oct 23
8582
1
Oct 23
97
1
Aug 23
2192