|
@@ -0,0 +1,343 @@
|
|
|
+openerp.partner_account_statement = function(instance) {
|
|
|
+ "use strict";
|
|
|
+ var model = openerp;
|
|
|
+ var record_id;
|
|
|
+
|
|
|
+ instance.web.FormView.include({
|
|
|
+ load_record: function(record) {
|
|
|
+ record_id = record.id
|
|
|
+ this._super.apply(this, arguments);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ instance.web.form.WidgetButton.include({
|
|
|
+ on_click: function() {
|
|
|
+ if (this.node.attrs.custom === "click_debt_paid") {
|
|
|
+ this.fetchInitial('get_debt_paid_ids');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.node.attrs.custom === "click_debt_pending") {
|
|
|
+ this.fetchInitial('get_debt_pending_ids');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.node.attrs.custom === "click_payment_done") {
|
|
|
+ this.fetchInitial('get_payment_done_ids');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.node.attrs.custom === "click_payment_pending") {
|
|
|
+ this.fetchInitial('get_payment_pending_ids');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._super();
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchInitial: function(method_name) {
|
|
|
+ var self = this;
|
|
|
+ this.fetchData(method_name).then(function(Data) {
|
|
|
+ return Data;
|
|
|
+ }).then(function(Data) {
|
|
|
+ self.Data = Data;
|
|
|
+ return self.fetchResCompany();
|
|
|
+ }).then(function(ResCompany) {
|
|
|
+ self.ResCompany = ResCompany
|
|
|
+ return self.fetchResCurrency();
|
|
|
+ }).then(function(ResCurrency) {
|
|
|
+ self.ResCurrency = ResCurrency
|
|
|
+ return self.fetchResPartner();
|
|
|
+ }).then(function(ResPartner) {
|
|
|
+ self.ResPartner = ResPartner
|
|
|
+ return self.clickOnAction(method_name);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResPartner: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new model.web.Model('res.partner');
|
|
|
+ var field = ['id', 'name',];
|
|
|
+ var domain = [
|
|
|
+ ['active','=',true],
|
|
|
+ ['id','=', record_id]
|
|
|
+ ]
|
|
|
+ currency.query(field).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResCompany: function() {
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var currency = new model.web.Model('res.company');
|
|
|
+ var field = ['id', 'name', 'currency_id', 'logo'];
|
|
|
+ currency.query(field).filter().all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchResCurrency : function(){
|
|
|
+ var self = this;
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var fields = ['id','name', 'symbol', 'decimal_separator', 'decimal_places', 'thousands_separator'];
|
|
|
+ var domain = [['active', '=', true]];
|
|
|
+ var ResCurrency = new model.web.Model('res.currency');
|
|
|
+ ResCurrency.query(fields).filter(domain).all().then(function(results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+ return defer;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchData: function(method_name) {
|
|
|
+ var domain = [
|
|
|
+ ['active','=',true],
|
|
|
+ ['id','=', record_id]
|
|
|
+ ]
|
|
|
+ var Data = new model.web.Model('res.partner');
|
|
|
+ return Data.call(method_name, [domain], {
|
|
|
+ context: new model.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getResCurrency: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ clickOnAction: function(method_name) {
|
|
|
+ var self = this;
|
|
|
+ var ResCompany;
|
|
|
+ var ResCompany = self.ResCompany[0];
|
|
|
+ var CurrencyBase = self.getResCurrency(self.ResCompany[0].currency_id[0]).shift();
|
|
|
+ if(method_name == 'get_debt_paid_ids'){
|
|
|
+ var getColumns = [{
|
|
|
+ 'title': 'Diario',
|
|
|
+ 'dataKey': 'journal_id'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Referencia',
|
|
|
+ 'dataKey': 'ref'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Asiento',
|
|
|
+ 'dataKey': 'move_id'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Fecha',
|
|
|
+ 'dataKey': 'date_created'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Monto',
|
|
|
+ 'dataKey': 'amount'
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+ var pdf_title = 'Cobros Realizados';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'cobros_realizados_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ journal_id: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ ref: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ move_id: {
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ date_created: {
|
|
|
+ columnWidth: 18,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ amount: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'right'
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ if(method_name == 'get_debt_pending_ids'){
|
|
|
+ var getColumns = [{
|
|
|
+ 'title': 'Diario',
|
|
|
+ 'dataKey': 'journal_id'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Referencia',
|
|
|
+ 'dataKey': 'ref'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Asiento',
|
|
|
+ 'dataKey': 'move_id'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Fecha de Vencimiento',
|
|
|
+ 'dataKey': 'date_maturity'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Monto',
|
|
|
+ 'dataKey': 'amount'
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+ var pdf_title = 'Cobros Pendientes';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'cobros_pendientes_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ journal_id: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ ref: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ move_id: {
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ date_maturity: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ amount: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'right'
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+ if(method_name == 'get_payment_done_ids'){
|
|
|
+ var getColumns = [{
|
|
|
+ 'title': 'Diario',
|
|
|
+ 'dataKey': 'journal_id'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Referencia',
|
|
|
+ 'dataKey': 'ref'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Asiento',
|
|
|
+ 'dataKey': 'move_id'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Fecha',
|
|
|
+ 'dataKey': 'date_created'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Monto',
|
|
|
+ 'dataKey': 'amount'
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+ var pdf_title = 'Pagos Realizados';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'pagos_realizados_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ journal_id: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ ref: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ move_id: {
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ date_created: {
|
|
|
+ columnWidth: 18,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ amount: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'right'
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+ if(method_name == 'get_payment_pending_ids'){
|
|
|
+ var getColumns = [{
|
|
|
+ 'title': 'Diario',
|
|
|
+ 'dataKey': 'journal_id'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Referencia',
|
|
|
+ 'dataKey': 'ref'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Asiento',
|
|
|
+ 'dataKey': 'move_id'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Fecha de Vencimiento',
|
|
|
+ 'dataKey': 'date_maturity'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'title': 'Monto',
|
|
|
+ 'dataKey': 'amount'
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+ var pdf_title = 'Pagos Pendientes';
|
|
|
+ var pdf_type = '';
|
|
|
+ var pdf_name = 'pagos_pendientes_';
|
|
|
+ var pdf_columnStyles = {
|
|
|
+ journal_id: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ ref: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ move_id: {
|
|
|
+ halign: 'left'
|
|
|
+ },
|
|
|
+ date_maturity: {
|
|
|
+ columnWidth: 30,
|
|
|
+ halign: 'center'
|
|
|
+ },
|
|
|
+ amount: {
|
|
|
+ columnWidth: 40,
|
|
|
+ halign: 'right'
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ var sum = _.map(self.Data, function(map){
|
|
|
+ return map.amount;
|
|
|
+ }).reduce(function(a, b){
|
|
|
+ return a + b;
|
|
|
+ });
|
|
|
+
|
|
|
+ var row = self.Data;
|
|
|
+ row.push({
|
|
|
+ 'journal_id': 'Total',
|
|
|
+ 'amount': accounting.formatMoney(sum,'', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ })
|
|
|
+ var filter = [];
|
|
|
+ filter.push({
|
|
|
+ title:'Cliente',
|
|
|
+ value: self.ResPartner[0].name,
|
|
|
+ });
|
|
|
+
|
|
|
+ var pdf = new model.eiru_reports.ReportPdfWidget(self);
|
|
|
+ pdf.drawPDF(
|
|
|
+ _.flatten(getColumns),
|
|
|
+ row,
|
|
|
+ ResCompany,
|
|
|
+ pdf_title,
|
|
|
+ pdf_type,
|
|
|
+ pdf_name,
|
|
|
+ pdf_columnStyles,
|
|
|
+ filter,
|
|
|
+ );
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|