Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
582 Zobrazení

i created a module for adding an custom tab named in odoo crm for adding products and while clicking on new quotation button we want to pass this product and credential to the quotation orderline..so here i will give the code 

from odoo import models, fields


class CrmLead(models.Model):
_inherit = 'crm.lead'

crm_sale_order_lines_ids = fields.One2many('crm.lead.quotation.management', 'lead_id')

def action_new_quotation(self):
action = super().action_new_quotation()
order_lines = []

for line in self.crm_sale_order_lines_ids:
default_tax_ids = line.product_id.taxes_id.ids if line.product_id else []

order_line_data = {
'product_id': line.product_id.id,
'name': line.description,
'product_uom_qty': line.ordered_quantity,
'price_unit': line.unit_price,
}

order_lines.append((0, 0, order_line_data))

action['context']['default_order_line'] = order_lines

return action

here i added the product fields for adding,,,how can i add the tax field there...not just default only..if i add new tax value it also must be moved to quotation orderline


Avatar
Zrušit
Nejlepší odpověď

Hi, 
To include the tax field in your quotation order line creation process and ensure that both default taxes and additional taxes are added when creating a new quotation, you can modify your code as follows:

1- Added tax_ids field 
2-cluded tax_id in order line data
3-Clearer field names

class CrmLead(models.Model):

    _inherit = 'crm.lead'


    crm_sale_order_lines_ids = fields.One2many(

        'crm.lead.quotation.management', 'lead_id', string="Quotation Products"

    )


    def action_new_quotation(self):

        action = super().action_new_quotation()

        order_lines = []


        for line in self.crm_sale_order_lines_ids:

            order_line_data = {

                'product_id': line.product_id.id,

                'name': line.description,

                'product_uom_qty': line.ordered_quantity,

                'price_unit': line.unit_price,

                'tax_id': [(6, 0, line.tax_ids.ids)],

            }


            order_lines.append((0, 0, order_line_data))


        action['context']['default_order_line'] = order_lines


        return action


class CrmLeadQuotationManagement(models.Model):

    _name = 'crm.lead.quotation.management'


    lead_id = fields.Many2one('crm.lead', string="Lead")

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

    description = fields.Text(string="Description")

    ordered_quantity = fields.Float(string="Ordered Quantity")

    unit_price = fields.Float(string="Unit Price")

    tax_ids = fields.Many2many('account.tax', string="Taxes")



Avatar
Zrušit
Autor

i never asked you to give me a code from chatgpt...i also knw that to check..