Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
6952 Widoki

I want to add a computed field "markup" to sale order lines in sale orders (quotes/sales orders).

I have created the model:

class SaleOrderLine(models.Model):
    _inherit = "sale.order.line"

    markup = fields.Float(compute='_compute_markup', digits=dp.get_precision('.2f%'), store=True)

    def _compute_markup(self, order_id, product_id, product_uom_id):
        frm_cur = self.env.user.company_id.currency_id
        to_cur = order_id.pricelist_id.currency_id
        purchase_price = product_id.standard_price
        if product_uom_id != product_id.uom_id:
            purchase_price = product_id.uom_id._compute_price(purchase_price, product_uom_id)
        ctx = self.env.context.copy()
        ctx['date'] = order_id.date_order
        price = frm_cur.with_context(ctx).compute(purchase_price, to_cur, round=False)
        return price


I want to add a computed field "markup" to sale order lines in sale orders (quotes/sales orders).

I have created the model:

class SaleOrderLine(models.Model):
    _inherit = "sale.order.line"

    markup = fields.Float(compute='_compute_markup', digits=dp.get_precision('.2f%'), store=True)

    def _compute_markup(self, order_id, product_id, product_uom_id):
        frm_cur = self.env.user.company_id.currency_id
        to_cur = order_id.pricelist_id.currency_id
        purchase_price = product_id.standard_price
        if product_uom_id != product_id.uom_id:
            purchase_price = product_id.uom_id._compute_price(purchase_price, product_uom_id)
        ctx = self.env.context.copy()
        ctx['date'] = order_id.date_order
        price = frm_cur.with_context(ctx).compute(purchase_price, to_cur, round=False)
        return price

And a new view which inherits sale.view_order_form:

<?xml version="1.0"?>
<odoo>
    <record id="view_order_form_margin" model="ir.ui.view">
        <field name="name">sale.order.form.margin</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="arch" type="xml">
            <xpath expr='//field[@name="order_line"]/form/group/group/field[@name="price_unit"]' position="before">
                <field name="markup"/>
            </xpath>
        </field>
    </record>
</odoo>

But the field is not shown (the view appears when you check views that inherit current view). I have reloaded everything, restarted the server and cleared the browser cache.

Any tip on why the field is not being shown is welcomed. Maybe the Xpath expression? Thanks.

Odoo 10.



Awatar
Odrzuć
Najlepsza odpowiedź

Hi EM,

Just make a slight change in the given Xpath like this, make it tree instead of form

<xpath expr="//field[@name='order_line']/tree//field[@name='price_unit']" position="before">
<field name="mark_up"/>
</xpath>

Hope this can help you,

Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
lis 23
7559
2
mar 22
9872
0
paź 20
3040
0
sie 21
3442
7
cze 21
13737