Skip to content

Commit

Permalink
[MERGE] forward port branch saas-16 up to aec6248
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Aug 23, 2017
2 parents 7f2bd08 + aec6248 commit 30bd5ac
Show file tree
Hide file tree
Showing 101 changed files with 2,300 additions and 375 deletions.
1 change: 0 additions & 1 deletion addons/account/models/account_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ def get_data_for_reconciliation_widget(self, excluded_ids=None):
'st_line': st_line.get_statement_line_for_reconciliation_widget(),
'reconciliation_proposition': rp
})

return ret

def get_statement_line_for_reconciliation_widget(self):
Expand Down
6 changes: 2 additions & 4 deletions addons/account/models/account_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ def set_values(self):
self.env.ref('base.group_user').write({'implied_ids': [(4, self.env.ref('product.group_sale_pricelist').id)]})
""" Set the product taxes if they have changed """
ir_values_obj = self.env['ir.values']
if self.default_sale_tax_id:
ir_values_obj.sudo().set_default('product.template', "taxes_id", [self.default_sale_tax_id.id], for_all_users=True, company_id=self.company_id.id)
if self.default_purchase_tax_id:
ir_values_obj.sudo().set_default('product.template', "supplier_taxes_id", [self.default_purchase_tax_id.id], for_all_users=True, company_id=self.company_id.id)
ir_values_obj.sudo().set_default('product.template', "taxes_id", [self.default_sale_tax_id.id] if self.default_sale_tax_id else False, for_all_users=True, company_id=self.company_id.id)
ir_values_obj.sudo().set_default('product.template', "supplier_taxes_id", [self.default_purchase_tax_id.id] if self.default_purchase_tax_id else False, for_all_users=True, company_id=self.company_id.id)
""" install a chart of accounts for the given company (if required) """
if self.chart_template_id and self.chart_template_id != self.company_id.chart_template_id:
wizard = self.env['wizard.multi.charts.accounts'].create({
Expand Down
8 changes: 4 additions & 4 deletions addons/account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ def _compute_payments(self):
related='partner_id.commercial_partner_id', store=True, readonly=True,
help="The commercial entity that will be used on Journal Entries for this invoice")

outstanding_credits_debits_widget = fields.Text(compute='_get_outstanding_info_JSON')
payments_widget = fields.Text(compute='_get_payment_info_JSON')
has_outstanding = fields.Boolean(compute='_get_outstanding_info_JSON')
outstanding_credits_debits_widget = fields.Text(compute='_get_outstanding_info_JSON', groups="account.group_account_invoice")
payments_widget = fields.Text(compute='_get_payment_info_JSON', groups="account.group_account_invoice")
has_outstanding = fields.Boolean(compute='_get_outstanding_info_JSON', groups="account.group_account_invoice")

#fields use to set the sequence, on the first invoice of the journal
sequence_number_next = fields.Char(string='Next Number', compute="_get_sequence_prefix", inverse="_set_sequence_next")
Expand Down Expand Up @@ -741,7 +741,7 @@ def assign_outstanding_credit(self, credit_aml_id):
self.ensure_one()
credit_aml = self.env['account.move.line'].browse(credit_aml_id)
if not credit_aml.currency_id and self.currency_id != self.company_id.currency_id:
credit_aml.with_context(allow_amount_currency=True).write({
credit_aml.with_context(allow_amount_currency=True, check_move_validity=False).write({
'amount_currency': self.company_id.currency_id.with_context(date=credit_aml.date).compute(credit_aml.balance, self.currency_id),
'currency_id': self.currency_id.id})
if credit_aml.payment_id:
Expand Down
2 changes: 1 addition & 1 deletion addons/account/static/src/js/account_payment_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var ShowPaymentLineWidget = AbstractField.extend({
k.index = v;
k.amount = field_utils.format.float(k.amount, {digits: k.digits});
if (k.date){
k.date = field_utils.format.date(field_utils.parse.date(k.date, {isUTC: true}));
k.date = field_utils.format.date(field_utils.parse.date(k.date, {}, {isUTC: true}));
}
});
this.$el.html(QWeb.render('ShowPaymentInfo', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var StatementAction = Widget.extend(ControlPanelMixin, {
validate_all_balanced: '_onValidate',
change_name: '_onChangeName',
close_statement: '_onCloseStatement',
load_more: '_onLoadMore',
},
config: {
// used to instanciate the model
Expand Down Expand Up @@ -71,6 +72,7 @@ var StatementAction = Widget.extend(ControlPanelMixin, {
'bank_statement_id': self.model.bank_statement_id,
'valuenow': self.model.valuenow,
'valuemax': self.model.valuemax,
'defaultDisplayQty': self.model.defaultDisplayQty,
'title': self.title,
});
});
Expand All @@ -89,12 +91,7 @@ var StatementAction = Widget.extend(ControlPanelMixin, {
this.update_control_panel({breadcrumbs: breadcrumbs, search_view_hidden: true}, {clear: true});

this.renderer.prependTo(self.$('.o_form_sheet'));
_.each(this.model.lines, function (line, handle) {
var widget = new self.config.LineRenderer(self, self.model, line);
widget.handle = handle;
self.widgets.push(widget);
widget.appendTo(self.$('.o_reconciliation_lines'));
});
this._renderLines();
this._openFirstLine();
},

Expand Down Expand Up @@ -134,6 +131,15 @@ var StatementAction = Widget.extend(ControlPanelMixin, {
return _.find(this.widgets, function (widget) {return widget.handle===handle;});
},

/**
*
*/
_loadMore: function(qty) {
var self = this;
return this.model.loadMore(qty).then(function () {
self._renderLines();
});
},
/**
* sitch to 'match' the first available line
*
Expand All @@ -153,6 +159,24 @@ var StatementAction = Widget.extend(ControlPanelMixin, {
}
return handle;
},
/**
* render line widget and append to view
*
* @private
*/
_renderLines: function () {
var self = this;
var linesToDisplay = this.model.getStatementLines();
_.each(linesToDisplay, function (line, handle) {
var widget = new self.config.LineRenderer(self, self.model, line);
widget.handle = handle;
self.widgets.push(widget);
widget.appendTo(self.$('.o_reconciliation_lines'));
});
if (this.model.hasMoreLines() === false) {
this.renderer.hideLoadMoreButton();
}
},

//--------------------------------------------------------------------------
// Handlers
Expand Down Expand Up @@ -223,6 +247,14 @@ var StatementAction = Widget.extend(ControlPanelMixin, {
});
});
},
/**
* Load more statement and render them
*
* @param {OdooEvent} event
*/
_onLoadMore: function (event) {
return this._loadMore(this.model.defaultDisplayQty);
},
/**
* call 'validate' or 'autoReconciliation' model method then destroy the
* validated lines and update the action renderer with the new status bar
Expand All @@ -246,7 +278,15 @@ var StatementAction = Widget.extend(ControlPanelMixin, {
});
_.each(result.handles, function (handle) {
self._getWidget(handle).destroy();
var index = _.findIndex(self.widgets, function (widget) {return widget.handle===handle;});
self.widgets.splice(index, 1);
});
// Get number of widget and if less than constant and if there are more to laod, load until constant
if (self.widgets.length < self.model.defaultDisplayQty
&& self.model.valuemax - self.model.valuenow >= self.model.defaultDisplayQty) {
var toLoad = self.model.defaultDisplayQty - self.widgets.length;
self._loadMore(toLoad);
}
self._openFirstLine();
});
},
Expand Down
100 changes: 90 additions & 10 deletions addons/account/static/src/js/reconciliation/reconciliation_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ var StatementModel = BasicModel.extend({
this.lines = {};
this.valuenow = 0;
this.valuemax = 0;
this.alreadyDisplayed = [];
this.defaultDisplayQty = 10;
},

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -230,10 +232,10 @@ var StatementModel = BasicModel.extend({
var line = this.getLine(handle);
line.st_line.partner_id = partner && partner.id;
line.st_line.partner_name = partner && partner.display_name || '';
return this._changePartner(handle, partner.id)
return $.when(partner && this._changePartner(handle, partner.id))
.then(function() {
line.reconciliation_proposition = [];
return self._performMoveLine(handle)
return self.changeMode(handle, 'match');
})
.then(function () {
if (line.mode === 'create') {
Expand All @@ -253,7 +255,7 @@ var StatementModel = BasicModel.extend({
args: [self.bank_statement_id.id],
})
.then(function () {
return self.bank_statement_id.id
return self.bank_statement_id.id;
});
},
/**
Expand Down Expand Up @@ -283,6 +285,34 @@ var StatementModel = BasicModel.extend({
getContext: function () {
return this.context;
},
/**
* Return the lines that needs to be displayed by the widget
*
* @returns {Object} lines that are loaded and not yet displayed
*/
getStatementLines: function () {
var self = this;
var linesToDisplay = _.pick(this.lines, function(value, key, object) {
if (value.visible === true && self.alreadyDisplayed.indexOf(key) === -1) {
self.alreadyDisplayed.push(key);
return object;
}
});
return linesToDisplay;
},
/**
* Return a boolean telling if load button needs to be displayed or not
*
* @returns {boolean} true if load more button needs to be displayed
*/
hasMoreLines: function () {
var self = this;
var notDisplayed = _.filter(this.lines, function(line) { return !line.visible; });
if (notDisplayed.length > 0) {
return true;
}
return false;
},
/**
* get the line data for this handle
*
Expand Down Expand Up @@ -355,14 +385,42 @@ var StatementModel = BasicModel.extend({
line.reconcileModels = self.reconcileModels;
});
var ids = _.pluck(self.lines, 'id');
return self._rpc({
model: 'account.bank.statement.line',
method: 'get_data_for_reconciliation_widget',
args: [ids],
})
.then(self._formatLine.bind(self));
ids = ids.splice(0, self.defaultDisplayQty);
self.pagerIndex = ids.length;
return self.loadData(ids, []);
});
},
/**
* Load more bank statement line
*
* @param {integer} quantity to load
* @returns {Deferred}
*/
loadMore: function(qty) {
if (qty === undefined) {
qty = this.defaultDisplayQty;
}
var ids = _.pluck(this.lines, 'id');
ids = ids.splice(this.pagerIndex, qty);
this.pagerIndex += qty;
return this.loadData(ids, this._getExcludedIds());
},
/**
* RPC method to load informations on lines
*
* @param {Array} ids of bank statement line passed to rpc call
* @param {Array} list of move_line ids that needs to be excluded from search
* @returns {Deferred}
*/
loadData: function(ids, excluded_ids) {
var self = this;
return self._rpc({
model: 'account.bank.statement.line',
method: 'get_data_for_reconciliation_widget',
args: [ids, excluded_ids],
})
.then(self._formatLine.bind(self));
},
/**
* Add lines into the propositions from the reconcile model
* Can add 2 lines, and each with its taxes. The second line become editable
Expand Down Expand Up @@ -770,6 +828,7 @@ var StatementModel = BasicModel.extend({
var line = _.find(self.lines, function (l) {
return l.id === data.st_line.id;
});
line.visible = true;
_.extend(line, data);
self._formatLineProposition(line, line.reconciliation_proposition);
if (!line.reconciliation_proposition.length) {
Expand Down Expand Up @@ -850,6 +909,26 @@ var StatementModel = BasicModel.extend({
prop.amount = prop.base_amount;
return prop;
},
/**
* Return list of account_move_line that has been selected and needs to be removed
* from other calls.
*
* @private
* @returns {Array} list of excluded ids
*/
_getExcludedIds: function () {
var excludedIds = [];
_.each(this.lines, function(line) {
if (line.reconciliation_proposition) {
_.each(line.reconciliation_proposition, function(prop) {
if (parseInt(prop['id'])) {
excludedIds.push(prop['id']);
}
})
}
});
return excludedIds;
},
/**
* Defined whether the line is to be displayed or not. Here, we only display
* the line if it comes from the server or if an account is defined when it
Expand Down Expand Up @@ -1168,7 +1247,8 @@ var ManualModel = StatementModel.extend({
'filter': "",
'reconcileModels': [],
'account_id': this._formatNameGet([data.account_id, data.account_name]),
'st_line': data
'st_line': data,
'visible': true
});
this._formatLineProposition(line, line.reconciliation_proposition);
if (!line.reconciliation_proposition.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var StatementRenderer = Widget.extend(FieldManagerMixin, {
"click *[rel='do_action']": "_onDoAction",
'click button.button_back_to_statement': '_onGoToBankStatement',
'click button.button_close_statement': '_onCloseBankStatement',
'click button.js_load_more': '_onLoadMore',
},
/**
* @override
Expand Down Expand Up @@ -87,6 +88,12 @@ var StatementRenderer = Widget.extend(FieldManagerMixin, {
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/*
* hide the button to load more statement line
*/
hideLoadMoreButton: function () {
this.$('.js_load_more').hide();
},
/**
* update the statement rendering
*
Expand Down Expand Up @@ -214,6 +221,14 @@ var StatementRenderer = Widget.extend(FieldManagerMixin, {
view_mode: 'form',
});
},
/**
* Load more statement lines for reconciliation
* @private
* @param {MouseEvent} event
*/
_onLoadMore: function (e) {
this.trigger_up('load_more');
},
/**
* @private
*/
Expand Down
3 changes: 1 addition & 2 deletions addons/account/static/src/less/account_reconciliation.less
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
vertical-align: top;
padding-right: 10px;
font-weight: bold;
white-space: nowrap;
}
}

Expand Down Expand Up @@ -209,7 +208,7 @@
.o-transition(max-height, 250ms);
}
&[data-mode="match"] > .match {
max-height: 130px;
max-height: none;
.o-transition(max-height, 400ms);
}
&[data-mode="create"] > .create {
Expand Down
14 changes: 13 additions & 1 deletion addons/account/static/src/xml/account_reconciliation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<div class="notification_area"/>
</div>
<div class="o_reconciliation_lines"/>
<div t-if="widget._initialState.valuemax > widget._initialState.defaultDisplayQty">
<button class="btn btn-default js_load_more">Load more</button>
</div>
<div class="pull-right text-muted">Tip: Hit CTRL-Enter to reconcile all the balanced items in the sheet.</div>
</div>
<div t-else="" class="o_view_nocontent">
Expand Down Expand Up @@ -203,7 +206,16 @@
<td class="cell_action"><span class="fa fa-add-remove"/></td>
<td class="cell_account_code"><t t-esc="line.account_code"/></td>
<td class="cell_due_date"><t t-esc="line.date_maturity === false ? line.date : line.date_maturity"/></td>
<td class="cell_label"><t t-if="line.partner_id &amp;&amp; line.partner_id !== state.st_line.partner_id"><t t-if="line.partner_name.length"><t t-esc="line.partner_name"/>: </t><t t-esc="line.label || line.name"/><t t-if="line.ref &amp;&amp; line.ref.length"> : </t><t t-esc="line.ref"/></t><t t-else=""><t t-esc="line.ref &amp;&amp; line.ref.length ? line.ref : line.label || line.name"/></t></td>
<td class="cell_label">
<t t-if="line.partner_id &amp;&amp; line.partner_id !== state.st_line.partner_id">
<t t-if="line.partner_name.length">
<t t-esc="line.partner_name"/>:
</t>
</t>
<t t-esc="line.label || line.name"/>
<t t-if="line.ref &amp;&amp; line.ref.length"> : </t>
<t t-esc="line.ref"/>
</td>
<td class="cell_left"><t t-if="line.amount &lt; 0"><span t-if="line.amount_currency_str" t-attf-class="o_multi_currency o_multi_currency_color_#{line.currency_id%8} line_info_button fa fa-money" t-att-data-content="line.amount_currency_str"/><t t-raw="line.amount_str"/></t></td>
<td class="cell_right"><t t-if="line.amount &gt; 0"><span t-if="line.amount_currency_str" t-attf-class="o_multi_currency o_multi_currency_color_#{line.currency_id%8} line_info_button fa fa-money" t-att-data-content="line.amount_currency_str"/><t t-raw="line.amount_str"/></t></td>
<td class="cell_info_popover"></td>
Expand Down
Loading

0 comments on commit 30bd5ac

Please sign in to comment.