Skip to Content
Menu
This question has been flagged

Hello Community,

I want to show validation error when the user export records for state='draft'(in one2many field). I have done code for it and it's working fine. but when I put this code for one2many table then I unable to get a validation message.

My code is below:

class DailyTransaction(models.Model):
_name = 'daily.transaction'
_rec_name = 'batch_id'

date = fields.Date()
batch_id = fields.Char()
daily_transaction = fields.One2many('transaction.log', 'daily_trans_log', string='Daily Transaction')


class Transaction_log(models.Model):
_name = 'transaction.log'
_rec_name = 'daily_trans_log'

daily_trans_log = fields.Many2one('daily.transaction')
log_status = fields.Selection([('Draft', 'Draft'), ('Approved', 'Approved'), ('Confirmed', 'Confirmed')],
default='Draft', string='Log Status')


odoo.define("transaction_log.export_log", function(require) {
"use strict";

var listController = require("web.ListController");
var dialog = require("web.Dialog");

listController.include({
/**
* Opens the Export Dialog
*
* @private
*/
_onExportData: function () {
var self = this;
var do_export = true;
// Avoid calling `read` when `state` field is not available
if (self.initialState.fields.hasOwnProperty('log_status')) {
self._rpc({
model: self.modelName,
method: 'read',
args: [self.getSelectedIds(), ['log_status']],
}).then(function (result) {
// Check if we have at least one draft record
for(var index in result) {
var item = result[index];
if (item.log_status === 'Draft') {
do_export = false;
break;
}
}
if (do_export) {
self._getExportDialogWidget().open();
} else {
dialog.alert(self, "You can't export draft stage data!", {});
}
});
} else {
this._getExportDialogWidget().open();
}
},
});

});

when I export record from 'transaction.log' for 'Draft' log_status then it's work and shows validation message. But I also want to show this validation when export from 'daily.transaction' 

Thanks in advance.


Avatar
Discard
Related Posts Replies Views Activity
0
Sep 24
147
0
Jan 20
2021
1
Nov 24
1615
0
Sep 23
144
2
Aug 23
19744