跳至内容
菜单
此问题已终结
2 回复
1101 查看

this is my code:

# pos_order_inherit.py

from odoo import models, fields, api

from odoo.exceptions import ValidationError

class PosOrderInherit(models.Model):

​ _inherit = 'pos.order' 

​_description = 'POS Order Inherit'

pos_number = fields.Char(string="Pos Number", readonly=True)

@api.model

​def create(self, vals): 

​if not vals.get('pos_number'): 

​vals['pos_number'] = self.env['ir.sequence'].next_by_code('pos.number.sequence') or '/' 

​return super(PosOrderInherit, self).create(vals)


# pos_order_inherit_view.xml
<?xml version="1.0" encoding="utf-8"?>

<odoo>

​<record id="seq_pos_number" model="ir.sequence">

​<field name="name">POS Number</field>

​<field name="code">pos.number.sequence</field>

​<field name="prefix">POS_NUMBER/</field>

​<field name="padding">5</field>

​<field name="company_id" eval="False"/>

​</record>


​<record id="pos_order_inherit_view_tree" model="ir.ui.view">

​ <field name="name">pos.order.tree.inherit</field>

​<field name="model">pos.order</field>

​<field name="inherit_id" ref="point_of_sale.view_pos_order_tree"/>

​<field name="arch" type="xml">

​<xpath expr="//field[@name='config_id']" position="after"> ​<field name="pos_number" readonly="1"/>

​</xpath>

​</field>

​</record>


​<record id="pos_order_inherit_view_form" model="ir.ui.view">

​<field name="name">pos.order.form.inherit</field>

​<field name="model">pos.order</field>

​ <field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/> <field name="arch" type="xml">

​<xpath expr="//field[@name='name']" position="after">

​<field name="pos_number" readonly="1"/>

​ </xpath>

​</field>

​</record>

​</odoo>


I want to show this inherited field to the receipt order on the PoS client

形象
丢弃
最佳答案

To display the custom pos_number field on the Point of Sale (PoS) receipt in Odoo, you need to extend the PoS client-side JavaScript and modify the receipt template. Odoo’s PoS uses a combination of Python (server-side) and JavaScript (client-side) to handle the receipt rendering. Since your field is already added to the pos.order model, you’ll need to:

  1. Extend the PoS data model to include the pos_number field in the client-side order data.
  2. Modify the receipt template to display the pos_number field.

形象
丢弃
最佳答案

Hello, Alam


    To show the custom field inherited in pos.order to the receipt order on the Point of Sale, please follow below steps.

   

        1) Create a Module, then create a folder structure of staic folder as shown in below image.

       

           

        2) Register the pos assets in __manifest__.py file.

   

         

        3) Print ' pos_order.py ' file add below code snippet.


               //Code 1 in comment//


        4) Print 'payment_screen.js' file add below code snippet.


                //Code 2 in comment//


        5) Print 'order_receipt.xml' file add below code snippet.


               //Code 3 in comment//


       6) Print 'models.js' file add below code snippet.


               //Code 4 in comment//


       7) Do not forget to replace 'your_module_name' to Actual module name in 'order_receipt.xml' file.

       


    Hope this helps !

     

    If you need any help in customization feel free to contact us.

       

 

    Thanks & Regards,

    Email:    odoo@aktivsoftware.com           

    Skype: kalpeshmaheshwari

形象
丢弃

Code 1 :

# -*- coding: utf-8 -*-

from odoo import api, models, fields

class PosOrder(models.Model):
_inherit = 'pos.order'

pos_number = fields.Char(string="Pos Number", readonly=True)

@api.model
def create(self,vals):
if not vals.get('pos_number'):
vals['pos_number'] = self.env['ir.sequence'].next_by_code('pos.number.sequence') or '/'
return super(PosOrder,self).create(vals)

def get_pos_number(self):
order = self.search([], limit=1, order='id desc')
pos_number = order.pos_number
return pos_number

Code 2 :

/* @odoo-module */

import { _t } from "@web/core/l10n/translation";
import { PaymentScreen } from "@point_of_sale/app/screens/payment_screen/payment_screen";
import { patch } from "@web/core/utils/patch";
import { OnlinePaymentPopup } from "@pos_online_payment/app/utils/online_payment_popup/online_payment_popup";
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup";
import { floatIsZero } from "@web/core/utils/numbers";
import { qrCodeSrc } from "@point_of_sale/utils";
import { useService } from "@web/core/utils/hooks";
import { useRef, onPatched, onMounted, useState } from "@odoo/owl";
import { usePos } from "@point_of_sale/app/store/pos_hook";

patch(PaymentScreen.prototype, {
setup() {
super.setup();
this.rpc = useService("rpc");
this.state = useState({ inputValue: this.props.startingValue });
this.pos = usePos();
this.popup = useService("popup");
this.userService = useService("user");
this.action = useService("action");
},

async afterOrderValidation(suggestToSync = false) {
const pos_number = this.pos.orders[0].server_id
const pos_number = await this.orm.call('payment.transaction', 'get_number_of_installment', [pos_number]);
this.pos.get_order().created_pos_number = pos_number
await super.afterOrderValidation(...arguments);
},

});

Code 3 :

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="your_module_name.OrderReceipt" t-inherit="point_of_sale.OrderReceipt" t-inherit-mode="extension">
<xpath expr="//div[hasclass('paymentlines')]" position="inside">
<t t-if="props.data.new_pos_number">
<h4>Session Name : <t t-esc="props.data.new_pos_number"/></h4>
</t>
</xpath>
</t>
</templates>

Code 4 :

/* @odoo-module */

import { Order } from "@point_of_sale/app/store/models";
import { usePos } from "@point_of_sale/app/store/pos_hook";
import { patch } from "@web/core/utils/patch";
import { useService } from "@web/core/utils/hooks";

patch(Order.prototype, {
export_for_printing() {
const result = super.export_for_printing(...arguments);
result.new_pos_number = this.pos.get_order().created_pos_number;
return result;
},

});