根据Odoo模块中的account / static / src / js / reconciliation_model.js文件,有一个对象分配:

var StatementModel = BasicModel.extend({
...
...
...

load: function (context) {
    var self = this;
    var statement_ids = context.statement_ids;
    if (!statement_ids) {
        return $.when();
    }
    this.context = context;

    var def_statement = this._rpc({
            model: 'account.bank.statement',
            method: 'reconciliation_widget_preprocess',
            args: [statement_ids],
        })
        .then(function (statement) {
            self.statement = statement;
            self.bank_statement_id = statement_ids.length === 1 ? {id: statement_ids[0], display_name: statement.statement_name} : false;
            self.valuenow = 0;
            self.valuemax = statement.st_lines_ids.length;
            self.context.journal_id = statement.journal_id;
            _.each(statement.st_lines_ids, function (id) {
                self.lines[_.uniqueId('rline')] = {
                    id: id,
                    reconciled: false,
                    mode: 'inactive',
                    mv_lines: [],
                    offset: 0,
                    filter: "",
                    reconciliation_proposition: [],
                    reconcileModels: [],
                };
            });
        });
    var def_reconcileModel = this._rpc({
            model: 'account.reconcile.model',
            method: 'search_read',
        })
        .then(function (reconcileModels) {
            self.reconcileModels = reconcileModels;
        });
    var def_account = this._rpc({
            model: 'account.account',
            method: 'search_read',
            fields: ['code'],
        })
        .then(function (accounts) {
            self.accounts = _.object(_.pluck(accounts, 'id'), _.pluck(accounts, 'code'));
        });
    return $.when(def_statement, def_reconcileModel, def_account).then(function () {
        _.each(self.lines, function (line) {
            line.reconcileModels = self.reconcileModels;
        });
        var ids = _.pluck(self.lines, 'id');
        ids = ids.splice(0, self.defaultDisplayQty);
        self.pagerIndex = ids.length;
        return self.loadData(ids, []);
    });
},
...
...
...
});


我想更改声明:

var def_statement = this._rpc({
        model: 'account.bank.statement',
        method: 'reconciliation_widget_preprocess',
        args: [statement_ids],
    })




var def_statement = this._rpc({
        model: 'account.bank.statement',
        method: 'reconciliation_widget_preprocess_with_line',
        args: [statement_ids, statement_line_ids],
    })


我的代码是这样的:

odoo.define('my_accounting.ReconciliationModel', function (require) {
    "use strict";

    var BasicModel = require('web.BasicModel');
    var field_utils = require('web.field_utils');
    var utils = require('web.utils');
    var session = require('web.session');
    var CrashManager = require('web.CrashManager');
    var core = require('web.core');
    var _t = core._t;
    var ReconciliationModel = require('account.ReconciliationModel');
    var StatementModel = ReconciliationModel.StatementModel;

    var MyStatementModel = StatementModel.extend({
        load: function (context) {
            var self = this;
            var statement_ids = context.statement_ids;
            if (!statement_ids) {
                return $.when();
            }
            var statement_line_ids = context.statement_line_ids;
            this.context = context;

            var def_statement = this._rpc({
                    model: 'account.bank.statement',
                    method: 'reconciliation_widget_preprocess_with_line',
                    args: [statement_ids, statement_line_ids],
                })
                .then(function (statement) {
                    self.statement = statement;
                    self.bank_statement_id = statement_ids.length === 1 ? {id: statement_ids[0], display_name: statement.statement_name} : false;
                    self.valuenow = 0;
                    self.valuemax = statement.st_lines_ids.length;
                    self.context.journal_id = statement.journal_id;
                    _.each(statement.st_lines_ids, function (id) {
                        self.lines[_.uniqueId('rline')] = {
                            id: id,
                            reconciled: false,
                            mode: 'inactive',
                            mv_lines: [],
                            offset: 0,
                            filter: "",
                            reconciliation_proposition: [],
                            reconcileModels: [],
                        };
                    });
                });
            var domainReconcile = [];
            if (context && context.company_ids) {
                domainReconcile.push(['company_id', 'in', context.company_ids]);
            }
            if (context && context.active_model === 'account.journal' && context.active_ids) {
                domainReconcile.push(['journal_id', 'in', [false].concat(context.active_ids)]);
            }
            var def_reconcileModel = this._rpc({
                    model: 'account.reconcile.model',
                    method: 'search_read',
                    domain: domainReconcile,
                })
                .then(function (reconcileModels) {
                    self.reconcileModels = reconcileModels;
                });
            var def_account = this._rpc({
                    model: 'account.account',
                    method: 'search_read',
                    fields: ['code'],
                })
                .then(function (accounts) {
                    self.accounts = _.object(_.pluck(accounts, 'id'), _.pluck(accounts, 'code'));
                });
            return $.when(def_statement, def_reconcileModel, def_account).then(function () {
                _.each(self.lines, function (line) {
                    line.reconcileModels = self.reconcileModels;
                });
                var ids = _.pluck(self.lines, 'id');
                ids = ids.splice(0, self.defaultDisplayQty);
                self.pagerIndex = ids.length;
                return self.loadData(ids, []);
            });
        }
    });
});


效果不好。我已经执行了模块升级,仍然在Odoo模块中调用了reconciliation_widget_preprocess方法而不是reconciliation_widget_preprocess_with_line

有人可以告诉我我想念的东西吗?我正在使用Odoo 11社区版。多谢您提供任何线索。

最佳答案

Patching an existing class时需要使用include方法。

var Hamster = require('web.Hamster');

Hamster.include({
    sleep: function () {
        this._super.apply(this, arguments);
        console.log('zzzz');
    },
});

关于javascript - 如何在account.ReconciliationModel中继承Odoo的StatementModel类?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60463780/

10-16 23:24