deisy 6 lat temu
commit
a75d60f1f3

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+import res_partner

BIN
__init__.pyc


+ 17 - 0
__openerp__.py

@@ -0,0 +1,17 @@
+# -*- coding:utf-8 -*-
+
+{
+    'name':'Partner Account Statement',
+    'author': "Deisy Samudio",
+    'depends':[
+        'base',
+        'account',
+        'account_followup'],
+    'data':[
+        'views/res_partner.xml',
+        'template.xml'
+        ],
+    'application':True,
+
+
+}

+ 96 - 0
res_partner.py

@@ -0,0 +1,96 @@
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields, api
+
+class res_partner(models.Model):
+    _inherit= 'res.partner'
+
+    total_debt_paid = fields.Float('Cobros Realizados:', compute='_compute_total_debt_paid', store=False)
+    total_payment = fields.Float('Pagos Realizados:',compute='_compute_total_payment', store=False)
+    debt_paid_ids = fields.One2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '!=', None), '&',('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')])
+    debt_pending_ids = fields.One2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '=', None), '&',('account_id.active','=', True), '&', ('account_id.type', '=', 'receivable'), ('state', '!=', 'draft')])
+    payment_done_ids = fields.One2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '!=', None), '&',('account_id.active','=', True), '&', ('account_id.type', '=', 'payable'), ('state', '!=', 'draft')])
+    payment_pending_ids = fields.One2many('account.move.line', 'partner_id', domain=['&', ('reconcile_id', '=', None), '&',('account_id.active','=', True), '&', ('account_id.type', '=', 'payable'), ('state', '!=', 'draft')])
+
+
+    def _compute_total_debt_paid(self):
+        res = {}
+        for partner in self:
+            suma = 0
+            account = self.env['account.voucher'].search([('partner_id','=',partner.id),('type','=','receipt'),('state','=','posted')])
+            for each in account:
+                suma = suma + each.amount
+            partner.total_debt_paid = suma
+            res = partner.total_debt_paid
+        return {'value': res}
+
+    def _compute_total_payment(self):
+        res = {}
+        for partner in self:
+            suma = 0
+            account = self.env['account.voucher'].search([('partner_id','=',partner.id),('type','=','payment'),('state','=','posted')])
+            for each in account:
+                suma = suma + each.amount
+            partner.total_payment = suma
+            res = partner.total_payment
+        return {'value': res}
+
+    @api.model
+    def get_debt_paid_ids(self, domain):
+        data = []
+        partner = self.env['res.partner'].search(domain)
+        for each in partner.debt_paid_ids:
+            print each
+            data.append({
+                'journal_id': each.journal_id.name,
+                'ref' : each.ref,
+                'move_id': each.move_id.name,
+                'date_created': each.date_created,
+                'amount': each.credit,
+                })
+        return data
+
+    @api.model
+    def get_debt_pending_ids(self, domain):
+        data = []
+        partner = self.env['res.partner'].search(domain)
+        for each in partner.debt_pending_ids:
+            print each
+            data.append({
+                'journal_id': each.journal_id.name,
+                'ref' : each.ref,
+                'move_id': each.move_id.name,
+                'date_maturity': each.date_maturity,
+                'amount': each.debit,
+                })
+        return data
+
+    @api.model
+    def get_payment_done_ids(self, domain):
+        data = []
+        partner = self.env['res.partner'].search(domain)
+        for each in partner.payment_done_ids:
+            print each
+            data.append({
+                'journal_id': each.journal_id.name,
+                'ref' : each.ref,
+                'move_id': each.move_id.name,
+                'date_created': each.date_created,
+                'amount': each.credit,
+                })
+        return data
+
+    @api.model
+    def get_payment_pending_ids(self, domain):
+        data = []
+        partner = self.env['res.partner'].search(domain)
+        for each in partner.payment_pending_ids:
+            print each
+            data.append({
+                'journal_id': each.journal_id.name,
+                'ref' : each.ref,
+                'move_id': each.move_id.name,
+                'date_maturity': each.date_maturity,
+                'amount': each.credit,
+                })
+        return data

BIN
res_partner.pyc


+ 0 - 0
static/src/css/custom.css


+ 103 - 0
static/src/js/partner_pdf.js

@@ -0,0 +1,103 @@
+// function partner_pdf(instance) {
+//     "use strict";
+//
+//     var model = openerp;
+//
+//     instance.ReportPdfWidget = instance.Base.extend({
+//       drawPDF: function (getColumns,row,ResCompany,pdf_title,pdf_type,pdf_name,pdf_columnStyles) {
+//         var self = this;
+//         var base64Img = 'data:image/png;base64,' + ResCompany.logo;
+//         var hoy = moment().format('DD/MM/YYYY');
+//         var totalPagesExp = "{total_pages_count_string}";
+//         var pdfDoc = new jsPDF(pdf_type);
+//         var y_position = 27;
+//         var y_position2 = 27;
+//
+//         //LOGO
+//         pdfDoc.addImage(base64Img, 'png', 7, 2, 0, 15);
+//
+//         //FECHA
+//         pdfDoc.setFontSize(13);
+//         pdfDoc.setFontStyle('normal');
+//         pdfDoc.setTextColor(40)
+//         pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 35, 12,hoy);
+//
+//         //TITULO
+//         pdfDoc.setFontSize(15);
+//         pdfDoc.setFontStyle('bold');
+//         pdfDoc.setTextColor('#0288d1');
+//         pdfDoc.autoTableText(pdf_title, pdfDoc.internal.pageSize.getWidth() - 12, 18, {
+//           halign: 'right',
+//           valign: 'middle'
+//         });
+//         pdfDoc.setLineWidth(0.5);
+//         pdfDoc.setDrawColor('#424242');
+//         pdfDoc.line(10, 22, pdfDoc.internal.pageSize.getWidth() - 10 , 22);
+//
+//         var i=0;
+//         if(pdf_type == 'l'){
+//           var col1_title = 15;
+//           var col1_value = 55;
+//           var col2_title = 150;
+//           var col2_value = 190;
+//         }
+//         else{
+//           var col1_title = 10;
+//           var col1_value = 50;
+//           var col2_title = 110;
+//           var col2_value = 150;
+//         }
+//
+//         pdfDoc.autoTable(getColumns, row, {
+//             // showHeader: 'firstPage',
+//             startY: y_position + 5,
+//             theme: 'grid',
+//             styles: {
+//                 overflow: 'linebreak',
+//                 columnWidth: 'auto',
+//                 fontSize: 7,
+//             },
+//             headerStyles: {
+//                 fillColor: [76, 133, 248],
+//                 fontSize: 9
+//             },
+//             columnStyles: pdf_columnStyles,
+//             margin: { horizontal: 7},
+//
+//             drawCell: function(cell, opts) {
+//                 var rows = opts.table.rows;
+//                 if (opts.row.index == rows.length - 1) {
+//                   pdfDoc.setFontStyle('bold');
+//                 }
+//             },
+//
+//             addPageContent: function (data) {
+//
+//             //FOOTER
+//                 var str = "Página " + data.pageCount;
+//                 if (typeof pdfDoc.putTotalPages === 'function') {
+//                     str = str + " de " + totalPagesExp;
+//                 }
+//                 pdfDoc.setFontSize(9);
+//                 pdfDoc.setFontStyle('bold');
+//                 pdfDoc.setTextColor(40);
+//                 var pageHeight = pdfDoc.internal.pageSize.height || pdfDoc.internal.pageSize.getHeight();
+//                 pdfDoc.autoTableText(str, pdfDoc.internal.pageSize.getWidth() - 35, pageHeight - 5, {
+//                   halign: 'rigth',
+//                   valign: 'middle'
+//                 });
+//             }
+//         });
+//         if (typeof pdfDoc.putTotalPages === 'function') {
+//             pdfDoc.putTotalPages(totalPagesExp);
+//         }
+//         row.pop();
+//         if(model.printer_bridge){
+//             var data = pdfDoc.output('datauristring');
+//             model.printer_bridge.print(data);
+//             return;
+//         }
+//         pdfDoc.save(pdf_name + hoy + '.pdf');
+//       },
+//
+// });

+ 343 - 0
static/src/js/report_account_statement.js

@@ -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,
+      );
+    },
+  });
+}

+ 11 - 0
template.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <template id="assets_backend" name="board assets" inherit_id="web.assets_backend">
+      <xpath expr="." position="inside">
+        <link rel="stylesheet" href="/partner_account_statement/static/src/css/custom.css"/>
+        <script type="text/javascript" src="/partner_account_statement/static/src/js/report_account_statement.js"/>
+      </xpath>
+    </template>
+  </data>
+</openerp>

+ 113 - 0
views/res_partner.xml

@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <record id="account_statement_page" model="ir.ui.view">
+      <field name="name">account_statement_page</field>
+      <field name="model">res.partner</field>
+      <field name="inherit_id" ref="base.view_partner_form"/>
+      <field name="arch" type="xml">
+        <notebook>
+          <page name="account_statement" string="Estado de Cuentas">
+            <notebook>
+              <page name="payments" string="Cobros Realizados" attrs="{'invisible':[('customer', '=', False)]}">
+                <group style="position:absolute; padding-top:10px;width: 500px;">
+                  <field name="total_debt_paid" string="Total cobros realizados" context="{'default_id': active_id}"/>
+                </group>
+                <div class="oe_right oe_button_box">
+                  <button id="btn_debt_paid" style="width:100% !important" class="oe_button oe_form_button" string="Imprimir Cobros Realizados" custom='click_debt_paid'/>
+                </div>
+                <field name="debt_paid_ids" readonly="1">
+                  <tree string="Account Move line" create="false" delete="false">
+                    <field name="journal_id"/>
+                    <field name="ref"/>
+                    <field name="move_id"/>
+                    <field name="date_created"/>
+                    <field name="credit" string="Monto"/>
+                  </tree>
+                </field>
+
+              </page>
+              <page name="receive" string="Pendientes de Cobro" attrs="{'invisible':[('customer', '=', False)]}">
+                <group style="position:absolute; padding-top:10px;width: 500px;">
+                    <field name="credit" string="Total cobros pendientes"/>
+                </group>
+                <div class="oe_right oe_button_box">
+                  <button id="btn_debt_pending" style="width:100% !important" class="oe_button oe_form_button" string="Imprimir Cobros Pendientes" custom='click_debt_pending'/>
+                </div>
+                <field name="debt_pending_ids" readonly="1">
+                  <tree string="Account Move line" editable="bottom" create="false" delete="false" colors="red:(not date_maturity or date_maturity&lt;=current_date) and debit&gt;0">
+                    <field name="journal_id"/>
+                    <field name="ref"/>
+                    <field name="move_id"/>
+                    <field name="date_maturity"/>
+                    <field name="debit" string="Monto"/>
+                  </tree>
+                </field>
+              </page>
+              <page name="payments1" string="Pagos Realizados" attrs="{'invisible':[('supplier', '=', False)]}">
+                <group style="position:absolute; padding-top:10px;width: 500px;">
+                  <field name="total_payment" string="Total pagos realizados" context="{'default_id': active_id}"/>
+                </group>
+
+                <div class="oe_right oe_button_box">
+                  <button id="btn_payment_done" style="width:100% !important" class="oe_button oe_form_button" string="Imprimir Pagos Realizados" custom='click_payment_done'/>
+                </div>
+                <field name="payment_done_ids" readonly="1">
+                  <tree string="Account Move line" create="false" delete="false">
+                    <field name="journal_id"/>
+                    <field name="ref"/>
+                    <field name="move_id"/>
+                    <field name="date_created"/>
+                    <field name="credit" string="Monto"/>
+                  </tree>
+                </field>
+              </page>
+              <page name="payments2" string="Pendientes de Pago" attrs="{'invisible':[('supplier', '=', False)]}">
+                <group style="position:absolute; padding-top:10px;width: 500px;">
+                 <field name="debit" string="Total pagos pendientes"/>
+               </group>
+                <div class="oe_right oe_button_box">
+                  <button id="btn_payment_pending" style="width:100% !important" class="oe_button oe_form_button" string="Imprimir Pagos Pendientes" custom='click_payment_pending'/>
+                </div>
+                <field name="payment_pending_ids" readonly="1">
+                  <tree string="Account Move line" editable="bottom" create="false" delete="false" colors="red:(not date_maturity or date_maturity&lt;=current_date) and credit&gt;0">
+                    <field name="journal_id"/>
+                    <field name="ref"/>
+                    <field name="move_id"/>
+                    <field name="date_maturity"/>
+                    <field name="credit" string="Monto"/>
+                  </tree>
+                </field>
+              </page>
+            </notebook>
+          </page>
+        </notebook>
+      </field>
+    </record>
+
+    <record id="account_statement_page3" model="ir.ui.view">
+       <field name="name">account_statement_page3</field>
+       <field name="model">res.partner</field>
+       <field name="inherit_id" ref="account.view_partner_property_form"/>
+       <field name="arch" type="xml">
+       <xpath expr="//field[@name='debit']" position="attributes">
+         <attribute name="invisible">True</attribute>
+       </xpath>
+       <xpath expr="//field[@name='credit']" position="attributes">
+         <attribute name="invisible">True</attribute>
+       </xpath>
+     </field>
+    </record>
+
+    <record id="account_statement_page2" model="ir.ui.view">
+      <field name="name">account_statement_page2</field>
+      <field name="model">res.partner</field>
+      <field name="inherit_id" ref="account_followup.view_partner_inherit_followup_form"/>
+      <field name="arch" type="xml">
+        <xpath expr="//page[@name='followup_tab']" position="attributes">
+         <attribute name="invisible">True</attribute>
+       </xpath>
+     </field>
+   </record>
+  </data>
+</openerp>