[FIX] account: add date field in reconciliation writeoff form

purpose:
    when creating a writeoff from the manual reconciliation widget (invoices & payment matching), there's no way to specify the date of the writeoff journal entry

specs:
    in v12, add a date field in the js and set the date of the writeoff entry accordingly

Was PR #29794
Was OPW 1896593

closes odoo/odoo#30676
This commit is contained in:
wan
2019-01-30 09:28:40 +00:00
committed by qdp-odoo
parent 0237654113
commit 3eead65f07
5 changed files with 28 additions and 6 deletions
+3 -2
View File
@@ -980,8 +980,9 @@ class AccountMoveLine(models.Model):
raise UserError(_("Either pass both debit and credit or none."))
if 'date' not in vals:
vals['date'] = self._context.get('date_p') or fields.Date.today()
if vals['date'] < date:
date = vals['date']
vals['date'] = fields.Date.to_date(vals['date'])
if vals['date'] and vals['date'] < date:
date = vals['date']
if 'name' not in vals:
vals['name'] = self._context.get('comment') or _('Write-Off')
if 'analytic_account_id' not in vals:
@@ -854,6 +854,7 @@ var StatementModel = BasicModel.extend({
'tax_id': [tax.id, null],
'amount': tax.amount,
'label': tax.name,
'date': prop.date,
'account_id': tax.account_id ? [tax.account_id, null] : prop.account_id,
'analytic': tax.analytic,
'is_tax': true,
@@ -1067,6 +1068,7 @@ var StatementModel = BasicModel.extend({
*/
_formatQuickCreate: function (line, values) {
values = values || {};
var today = new moment().utc().format();
var account = this._formatNameGet(values.account_id);
var formatOptions = {
currency_id: line.st_line.currency_id,
@@ -1083,6 +1085,7 @@ var StatementModel = BasicModel.extend({
'tax_id': this._formatNameGet(values.tax_id),
'debit': 0,
'credit': 0,
'date': values.date ? values.date : field_utils.parse.date(today, {}, {isUTC: true}),
'base_amount': values.amount_type !== "percentage" ?
(amount) : line.balance.amount * values.amount / 100,
'percent': values.amount_type === "percentage" ? values.amount : null,
@@ -1233,7 +1236,7 @@ var StatementModel = BasicModel.extend({
* datas allowing manual reconciliation
*/
var ManualModel = StatementModel.extend({
quickCreateFields: ['account_id', 'journal_id', 'amount', 'analytic_account_id', 'label', 'tax_id', 'force_tax_included', 'analytic_tag_ids'],
quickCreateFields: ['account_id', 'journal_id', 'amount', 'analytic_account_id', 'label', 'tax_id', 'force_tax_included', 'analytic_tag_ids', 'date'],
//--------------------------------------------------------------------------
// Public
@@ -1628,6 +1631,12 @@ var ManualModel = StatementModel.extend({
})
.then(this._formatMoveLine.bind(this, handle));
},
_formatToProcessReconciliation: function (line, prop) {
var result = this._super(line, prop);
result['date'] = prop.date;
return result;
},
});
return {
@@ -556,10 +556,13 @@ var LineRenderer = Widget.extend(FieldManagerMixin, {
}, {
type: 'float',
name: 'amount',
}, {
type: 'char', //TODO is it a bug or a feature when type date exists ?
name: 'date',
}], {
account_id: {string: _t("Account")},
label: {string: _t("Label")},
amount: {string: _t("Account")}
amount: {string: _t("Account")},
}).then(function (recordID) {
self.handleCreateRecord = recordID;
var record = self.model.get(self.handleCreateRecord);
@@ -587,6 +590,9 @@ var LineRenderer = Widget.extend(FieldManagerMixin, {
self.fields.amount = new basic_fields.FieldFloat(self,
'amount', record, {mode: 'edit'});
self.fields.date = new basic_fields.FieldDate(self,
'date', record, {mode: 'edit'});
var $create = $(qweb.render("reconciliation.line.create", {'state': state}));
self.fields.account_id.appendTo($create.find('.create_account_id .o_td_field'))
@@ -600,6 +606,7 @@ var LineRenderer = Widget.extend(FieldManagerMixin, {
.then(addRequiredStyle.bind(self, self.fields.label));
self.fields.amount.appendTo($create.find('.create_amount .o_td_field'))
.then(addRequiredStyle.bind(self, self.fields.amount));
self.fields.date.appendTo($create.find('.create_date .o_td_field'))
self.$('.create').append($create);
function addRequiredStyle(widget) {
@@ -888,6 +895,7 @@ var ManualLineRenderer = LineRenderer.extend({
_renderCreate: function (state) {
this._super(state);
this.$('.create .create_journal_id').show();
this.$('.create .create_date').removeClass('d-none')
this.$('.create .create_journal_id .o_input').addClass('o_required_modifier');
},
@@ -212,6 +212,10 @@
<td class="o_td_label">Tax Included in Price</td>
<td class="o_td_field"></td>
</tr>
<tr class="create_date d-none">
<td class="o_td_label">Writeoff Date</td>
<td class="o_td_field"></td>
</tr>
</tbody>
</table>
<div class="add_line_container">
@@ -650,8 +650,8 @@ QUnit.module('account', {
assert.strictEqual(widget.$('.o_input_dropdown input').val(), "Agrolait", "the partner many2one should display agrolait");
assert.strictEqual(clientAction.widgets[2].$('.o_input_dropdown input').val(), "Camptocamp", "the partner many2one should display Camptocamp");
widget.$('.accounting_view tfoot td:first').trigger('click');
assert.strictEqual(widget.$('.create input.o_input').length, 7,
"create panel should contain 7 fields (account_id, tax_id, journal_id, analytic_account_id, analytic_tag_ids, label, amount)");
assert.strictEqual(widget.$('.create input.o_input').length, 8,
"create panel should contain 7 fields (account_id, tax_id, journal_id, analytic_account_id, analytic_tag_ids, label, amount, date)");
assert.strictEqual(widget.$('.create .create_account_id .o_required_modifier, .create .create_label .o_required_modifier, .create .create_amount .o_required_modifier').length, 3,
"account_id, label and amount should be required fields");
assert.strictEqual(widget.$('.create .create_label input').val(), 'SAJ/2014/002 and SAJ/2014/003',