Skip to Content
Menu
This question has been flagged

Here is my case. I want to add a field named partner_id(string =’vendor’s name’, widget =many2one) from purchase.order after the field “name” in page in purchase.order.line. Also when I select a product, it will show me that product name. But whatever I am trying, its not working. Here its not the case the first vendor will be shown. Whoever has that product, the Id will be shown.

I have also used onchange method but still not working. Please, resolve this problem.

here my code:

for vedor:

 rom odoo import models, fields, api

class PurchaseOrderLine(models.Model):


    _inherit = 'purchase.order.line'    


    agent_price = fields.Monetary(string="Vendor's Price", compute='_compute_agent_price', store=True) 


    partner_id = fields.Many2one('res.partner', string="Vendor", compute='_compute_partner_id', store=True)


                

    @api.depends('order_id.partner_id', 'product_id')


    def _compute_agent_price(self):


        for line in self:


            if line.order_id.partner_id and line.product_id:


                vendor = line.order_id.partner_id


                product = line.product_id


                agent_price = vendor.purchase_line_ids.filtered(lambda x: x.product_id == product).agent_price


                line.agent_price = agent_price or 0.0


            else:


                line.agent_price = 0.0


    @api.depends('product_qty', 'agent_price', 'taxes_id')


    def _compute_amount(self):


        for line in self:


            tax_results = self.env['account.tax']._compute_taxes([line._convert_to_tax_base_line_dict()])


            totals = list(tax_results['totals'].values())[0]


            amount_untaxed = totals['amount_untaxed']


            amount_tax = totals['amount_tax']


            line.update({


                'price_subtotal': amount_untaxed,


                'price_tax': amount_tax,


                'price_total': amount_untaxed + amount_tax,


            })




    def _convert_to_tax_base_line_dict(self):


        """ Convert the current record to a dictionary in order to use the generic taxes computation method


        defined on account.tax.




        :return: A python dictionary.


        """


        self.ensure_one()


        return self.env['account.tax']._convert_to_tax_base_line_dict(


            self,


            partner=self.order_id.partner_id,


            currency=self.order_id.currency_id,


            product=self.product_id,


            taxes=self.taxes_id,


            price_unit=self.agent_price,


            quantity=self.product_qty,


            price_subtotal=self.price_subtotal,


        )


for addquantity:

from odoo import models, fields, api,_


from odoo.exceptions import ValidationError




##for vendor


class PurchaseLine(models.Model):


    _inherit = 'res.partner'




    purchase_line_ids = fields.One2many('purchase.line', 'purchase_line_id', string='Order Lines', edit="inline")




class CustomPurchaseLine(models.Model):


    _name = 'purchase.line'


    _description = 'Custom Purchase Line'




    purchase_line_id = fields.Many2one('res.partner', string='Vendor', required=True)


    ###in editview form of RFQ page,in line 89, invisible=1 is used


    product_id = fields.Many2one('product.product', string='Product', required=True)


    currency_id = fields.Many2one('res.currency', string='Currency')


    agent_price = fields.Monetary(string="Vendor's Price", currency_field='currency_id')

Avatar
Discard
Related Posts Replies Views Activity
1
Sep 21
7103
1
Dec 20
3575
0
Jan 24
2061
1
Aug 22
4193
2
Oct 20
2999