Как наследовать класс StatementModel в Odoo в account.ReconciliationModel? - PullRequest
0 голосов
/ 29 февраля 2020

В соответствии с файлом account / static / src / js / reconciliation_model. js в модуле Odoo существует назначение объекта:

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, []);
            });
        }
    });
});

Он не работает хорошо. Я выполнил обновление моего модуля и все еще вызываю метод reconciliation_widget_preprocess вместо reconciliation_widget_preprocess_with_line в моем модуле Odoo.

Может кто-нибудь сказать мне, что я пропустил? Я использую Odoo 11 Community Edition. Я благодарю вас за любую подсказку.

1 Ответ

1 голос
/ 03 марта 2020

Вам необходимо использовать метод include при Исправлении существующего класса .

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

Hamster.include({
    sleep: function () {
        this._super.apply(this, arguments);
        console.log('zzzz');
    },
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...