3

models_extend.js

 odoo.define('pos_ticket.models_extend', function (require) {
    "use strict";

    var x = require('point_of_sale.models');
    var models = pos_model.PosModel.prototype.models;

    models.push(
            {
             model:  'res.company',
            fields: [ 'currency_id', 'email', 'website', 'company_registry', 'vat', 'name', 'phone', 'partner_id' , 'country_id', 'tax_calculation_rounding_method','city','trn_no'],
            ids:    function(self){ return [self.user.company_id[0]]; },
            loaded: function(self,companies){ self.company = companies[0]; },
            },

            {
             model:  'product.product',
             fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'default_code', 
                     'to_weight', 'uom_id', 'description_sale', 'description',
                     'product_tmpl_id','tracking','arb'],
            order:  ['sequence','default_code','name'],
            domain: [['sale_ok','=',true],['available_in_pos','=',true]],
            context: function(self){ return { pricelist: self.pricelist.id, display_default_code: false }; },
            loaded: function(self, products){
                self.db.add_products(products);
            },
            },
            {
            model:  'product.product',
            fields: ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'default_code', 
                     'to_weight', 'uom_id', 'description_sale', 'description',
                     'product_tmpl_id','tracking','arb'],
            order:  ['sequence','default_code','name'],
            domain: [['sale_ok','=',true],['available_in_pos','=',true]],
            context: function(self){ return { pricelist: self.pricelist.id, display_default_code: false }; },
            loaded: function(self, products){
                self.db.add_products(products);
                },
            }
            );

    x.Order = x.Order.extend({

            export_for_printing: function(){
            var self = this;
            this.pos = options.pos;
            var company = this.pos.company;

            var receipt = {

                company:{
                    city:company.city,
                    trn_no:company.trn_no,
                }

            }

            return receipt;
        },
    });

I want to add city and trn_no in res.company and arb in product.product to see the arabic translation.Then only i can submit my project in time, i am literally trapped please help me .i am a trainee . To add new field in POS modules necessary in models.js override PosModel in the parent models which we take from “point_of_sale.models”.

After some changes

odoo.define('pos_ticket.models_extend', function (require) {
"use strict";

var x = require('point_of_sale.models');

var _super = x.PosModel.prototype;
    module.PosModel = x.PosModel.extend({
     initialize: function (session, attributes) {
        // call super to set all properties
        _super.initialize.apply(this, arguments);
        // here i can access the models list like this and add an element.
        this.models.push(
        {
        // load allowed users
            model:  'res.company',
            fields: ['city','trn_no'],
            domain: function(self){ return [['id','in',self.users.company_id]]; },
            loaded: function(self,companies){
                console.log(companies);
                self.allowed_users = companies;
         }
         },{
        model:  'product.product',
        fields: ['arb'],
        order:  ['sequence','default_code','name'],
        domain: [['sale_ok','=',true],['available_in_pos','=',true]],
        context: function(self){ return { pricelist: self.pricelist.id, display_default_code: false }; },
        loaded: function(self, products){
            self.db.add_products(products);
        }
    },
    )
      return this;
  }
});


});

now i need to inherit another function called "export_for_printing" and add those new fields in it so that i can print these fields.how?

1 Answers1

1

Just add the modifications to the self.models array like this. This works for the version 8. Maybe it you need to adapt it:

if (typeof jQuery === 'undefined') { throw new Error('Product multi POS needs jQuery'); }

+function ($) {
    'use strict';

    openerp.your_module_name = function(instance, module) {
        var PosModelParent = instance.point_of_sale.PosModel;
        instance.point_of_sale.PosModel = instance.point_of_sale.PosModel.extend({
            load_server_data: function(){
                var self = this;

                self.models.forEach(function(elem) {
                    if (elem.model == 'res.company') {
                        elem.fields = // make your new assignations here
                        elem.domain = // ...
                        elem.loaded = // ...
                    } else if (elem.model == 'product.product') {
                        // [...]
                    }
                })

                var loaded = PosModelParent.prototype.load_server_data.apply(this, arguments);
                return loaded;
            },

        });
    }
}(jQuery);
ChesuCR
  • 9,352
  • 5
  • 51
  • 114