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

I would like to add the internal reference next to the product name: 

Avatar
Discard
Best Answer

Hi,


To add the internal reference (default_code) next to the product name in the POS orderline, follow the steps below:


1. Update the getDisplayData() method of PosOrderline to include the default_code field:


JavaScript:


import { PosOrderline } from "@point_of_sale/app/models/pos_order_line";

import { patch } from "@web/core/utils/patch";


patch(PosOrderline.prototype, {

    getDisplayData() {

        return {

            ...super.getDisplayData(),

            default_code: this.product_id.default_code,

        };

    },

});


2. Inherit the point_of_sale.Orderline template and add the default_code next to the product name:


XML:


<?xml version="1.0" encoding="UTF-8"?>

<templates id="template" xml:space="preserve">

    <t t-name="pos_sale.Orderline.internal_reference" t-inherit="point_of_sale.Orderline" t-inherit-mode="extension">

        <xpath expr="//div[contains(@class, 'product-ref')]/span" position="after">

            <span t-if="line.default_code" class="product-default-code text-muted">

                (<t t-esc="line.default_code"/>)

            </span>

        </xpath>

    </t>

</templates>


Ensure the JavaScript and XML files are properly added in the manifest:


'assets': {

        'point_of_sale._assets_pos': [

            '/path/to/js/file',

            '/path/to/xml/file',

        ],

    },



Hope it helps

Avatar
Discard
Author

Hi there. I tried. But I get the error when opening the pos: The following modules failed to load because of an error, you may find more information in the devtools console: point_of_sale.assets_prod.bundle.xml

You can see my module on: https://github.com/sky69006/dataforge

the module name is 'custom_werk_fmoda'.

am I doing something wrong?

Best Answer

Hello, Olivier Biltris,


To add the internal reference next to the product name, follow the steps outlined below:


1. Inherit and Extend the Orderline Model

Objective: Display the internal reference (product's default_code) next to the product name.


File: static/src/app/store/models/orderline.js


//Code1 in comment//


2. Modify the POS XML Template


Objective: Show the internal reference next to the product name in the Orderline.


File: static/src/app/store/models/orderline.xml


//Code2 in comment//


3. Update the __manifest__.py File


File: __manifest__.py


//Code3 in comment//


4. Output

Once implemented, the internal reference (default_code) will be displayed next to the product name in the Point of Sale screen. Below is an example of how it will appear:




Hope this helps! If you need further assistance with customization, feel free to contact us.


Thanks & Regards,

Email:   odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

Avatar
Discard

Code 1:

/* @odoo-module /

import { Orderline } from "@point_of_sale/app/store/models";
import { patch } from "@web/core/utils/patch";

// Extend Orderline's `getDisplayData` method
patch(Orderline.prototype, {
getDisplayData() {
return {
...super.getDisplayData(),
reference: this.product.default_code,
};
},
});

Code 2:

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-inherit="point_of_sale.Orderline" t-inherit-mode="extension">
<xpath expr="//span[contains(@t-esc, 'line.productName')]" position="after">
//display product reference after roduct name
<span t-if="line.reference"> - <t t-esc="line.reference"/></span>
</xpath>
</t>
</templates>

Code 3:

assets': {
'point_of_sale._assets_pos': [
'your_module_name/static/src/**/*',
],
},
Add the path to the new JavaScript and XML files under the point_of_sale._assets_pos key.