I've added a new field in sale.order.line and pos.order.line called "resource_name" I want to show it in the printed POS receipt, it came always empty. even in the DB it's correctly set in both tables. even when i try to console.log it it appears Undefined
sale.order.line:
from odoo import fields, models
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
resource_name = fields.Char(string="Specialist Name")
pos.order.line:
from odoo import fields, models
class PosOrderLine(models.Model):
_inherit = 'pos.order.line'
resource_name = fields.Char(string="Specialist Name")
def _order_line_fields(self, line, session_id=None):
result = super(PosOrderLine, self)._order_line_fields(line, session_id)
vals = result[2]
if vals.get('sale_order_line_id'):
order_line_id = vals.get('sale_order_line_id')
order_line = self.env['sale.order.line'].browse(order_line_id)
if order_line:
if order_line.resource_name:
resource_name_exp = order_line.resource_name
vals['resource_name'] = resource_name_exp
return result
def _export_for_ui(self, orderline):
result = super(PosOrderLine, self)._export_for_ui(orderline)
result.update({
'resource_name': orderline.resource_name,
})
return result
JS:
odoo.define('pos_invoice_ksa.model', function (require) {
'use strict';
var pos_model = require("point_of_sale.models");
var SuperOrderLine = pos_model.Orderline.prototype;
pos_model.load_fields("pos.order.line", ["resource_name"]);
pos_model.Orderline = pos_model.Orderline.extend({
initialize: function(attr, options) {
SuperOrderLine.initialize.call(this,attr,options);
this.resource_name = this.resource_name || "";
},
export_for_printing: function(){
var json = SuperOrderLine.export_for_printing.call(this);
json.resource_name = this.resource_name;
return json;
},
});
});
for the XML, I have already a working inheritance: I simply added a new cloumn and used :
<tr t-foreach="orderlines" t-as="orderline" t-key="orderline.id">
<!-- working code -->
<td style='text-align:right'>
<t t-esc="orderline.resource_name"/>
</td>
<!-- working code -->
Try to get the resource_name
from options
in the initialize
function
Example:
this.resource_name = this.resource_name || options.json.resource_name;