I’m using Odoo 17 pos I’ve added new field called is_void, I want to access this field from the receipt, It comes with undefined (empty), but It sent to the DB Correctly here is my code below:
Python:
from odoo import models, fields
class PosOrderLine(models.Model):
_inherit = "pos.order.line"
is_void = fields.Boolean(
string="Is Void",
default=False,
help="Indicates whether this line is voided or not.",
)
def _order_line_fields(self, line, session_id=None):
result = super(PosOrderLine, self)._order_line_fields(line, session_id)
result["is_void"] = line.get("is_void", False)
return result
def _export_for_ui(self, orderline):
result = super()._export_for_ui(orderline)
result.update(
{
"is_void": orderline.is_void,
}
)
return result
Javascript:
patch(Orderline.prototype, {
constructor() {
this.is_void = this.is_void || false;
},
// // Toggle the is_void flag
toggleVoid() {
this.is_void = !this.is_void;
},
// Include is_void in export_as_JSON
export_as_JSON() {
const result = super.export_as_JSON(...arguments);
result["is_void"] = this.is_void;
return result;
},
init_from_JSON(json) {
super.init_from_JSON(...arguments);
this.is_void = json.is_void || false;
},
export_for_printing() {
const json = this._super(...arguments);
json.is_void = this.is_void;
return json;
},
});
Getting the below error
point_of_sale.assets_prod.min.js:9701 Failed to send orders: [{…}]
_save_to_server @ point_of_sale.assets_prod.min.js:9701
RPC_ERROR://localhost:8069/web/assets/7b7dc0e/point_of_sale.assets_prod.min.js:6586:163)
at XMLHttpRequest.<anonymous> (http://localhost:8069/web/assets/7b7dc0e/point_of_sale.assets_prod.min.js:6590:13)
Also I tried to load_params but this solution works only if the custom field is predefined not defined or set its value during making the order itself.