[PYTHON][VIEW][REPORT] +print custom report when order is cpv master
authorLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Wed, 27 May 2020 10:27:56 +0000 (12:27 +0200)
committerLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Wed, 27 May 2020 10:27:56 +0000 (12:27 +0200)
__init__.py
__openerp__.py
data/ir_values.xml [deleted file]
i18n/coup_de_pouce_velo.pot [new file with mode: 0644]
i18n/fr.po [new file with mode: 0644]
report/__init__.py [new file with mode: 0644]
report/pos_receipt.py [new file with mode: 0644]
report/pos_receipt_coup_de_pouce_velo.rml [new file with mode: 0644]
wizard/pos_receipt.py

index ca6fde1..5b2378b 100644 (file)
@@ -2,4 +2,5 @@
 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
 
 import point_of_sale
+import report
 import wizard
index eb16b6d..34bb296 100644 (file)
@@ -25,7 +25,6 @@ This module adds features to OpenERP POS module for french bikecoops for "Coup d
     ],
     'update_xml': [
         'view/point_of_sale.xml',
-        'data/ir_values.xml',
     ],
     'installable': True,
     'auto_install': False,
diff --git a/data/ir_values.xml b/data/ir_values.xml
deleted file mode 100644 (file)
index f004672..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<openerp>
-    <data noupdate="1">
-        <record id="cpv_default_note" model="ir.values">
-            <field name="name">note</field>
-            <field name="key">default</field>
-            <field name="key2">is_cpv=true</field>
-            <field name="model">pos.order</field>
-            <field name="value_unpickle">"Entretien vélo dans le cadre du «Coup de pouce Vélo - Autoréparation»"</field>
-        </record>
-    </data>
-</openerp>
diff --git a/i18n/coup_de_pouce_velo.pot b/i18n/coup_de_pouce_velo.pot
new file mode 100644 (file)
index 0000000..170b4a4
--- /dev/null
@@ -0,0 +1,38 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#      * coup_de_pouce_velo
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2020-05-27 10:22+0000\n"
+"PO-Revision-Date: 2020-05-27 10:22+0000\n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: coup_de_pouce_velo
+#: field:pos.order,is_cpv:0
+msgid "\"Coup de Pouce Velo\"?"
+msgstr ""
+
+#. module: coup_de_pouce_velo
+#: model:ir.model,name:coup_de_pouce_velo.model_pos_order
+msgid "Point of Sale"
+msgstr ""
+
+#. module: coup_de_pouce_velo
+#: code:addons/coup_de_pouce_velo/point_of_sale.py:26
+#, python-format
+msgid "Warning"
+msgstr ""
+
+#. module: coup_de_pouce_velo
+#: model:ir.model,name:coup_de_pouce_velo.model_pos_receipt
+msgid "Point of sale receipt"
+msgstr ""
+
diff --git a/i18n/fr.po b/i18n/fr.po
new file mode 100644 (file)
index 0000000..093f605
--- /dev/null
@@ -0,0 +1,39 @@
+# Translation of OpenERP Server.
+# This file contains the translation of the following modules:
+#      * coup_de_pouce_velo
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: OpenERP Server 7.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2020-05-27 10:22+0000\n"
+"PO-Revision-Date: 2020-05-27 12:23+0200\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+"X-Generator: Poedit 2.3.1\n"
+"Last-Translator: Ludovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>\n"
+"Language: fr\n"
+
+#. module: coup_de_pouce_velo
+#: field:pos.order,is_cpv:0
+msgid "\"Coup de Pouce Velo\"?"
+msgstr "\"Coup de Pouce Vélo\"?"
+
+#. module: coup_de_pouce_velo
+#: model:ir.model,name:coup_de_pouce_velo.model_pos_order
+msgid "Point of Sale"
+msgstr "Atelier"
+
+#. module: coup_de_pouce_velo
+#: code:addons/coup_de_pouce_velo/point_of_sale.py:26
+#, python-format
+msgid "Warning"
+msgstr "Avertissement"
+
+#. module: coup_de_pouce_velo
+#: model:ir.model,name:coup_de_pouce_velo.model_pos_receipt
+msgid "Point of sale receipt"
+msgstr "Reçu de l'atelier"
diff --git a/report/__init__.py b/report/__init__.py
new file mode 100644 (file)
index 0000000..630cf01
--- /dev/null
@@ -0,0 +1,4 @@
+# Copyright 2020 L'Heureux Cyclage
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+import pos_receipt
diff --git a/report/pos_receipt.py b/report/pos_receipt.py
new file mode 100644 (file)
index 0000000..b9e3c2a
--- /dev/null
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+
+import time
+from openerp.report import report_sxw
+from openerp import pooler
+
+def titlize(journal_name):
+    words = journal_name.split()
+    while words.pop() != 'journal':
+        continue
+    return ' '.join(words)
+
+class order(report_sxw.rml_parse):
+
+    def __init__(self, cr, uid, name, context):
+        super(order, self).__init__(cr, uid, name, context=context)
+
+        user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
+        partner = user.company_id.partner_id
+
+        self.localcontext.update({
+            'time': time,
+            'disc': self.discount,
+            'net': self.netamount,
+            'get_journal_amt': self._get_journal_amt,
+            'address': partner or False,
+            'titlize': titlize
+        })
+
+    def netamount(self, order_line_id):
+        sql = 'select (qty*price_unit) as net_price from pos_order_line where id = %s'
+        self.cr.execute(sql, (order_line_id,))
+        res = self.cr.fetchone()
+        return res[0]
+
+    def discount(self, order_id):
+        sql = 'select discount, price_unit, qty from pos_order_line where order_id = %s '
+        self.cr.execute(sql, (order_id,))
+        res = self.cr.fetchall()
+        dsum = 0
+        for line in res:
+            if line[0] != 0:
+                dsum = dsum +(line[2] * (line[0]*line[1]/100))
+        return dsum
+
+    def _get_journal_amt(self, order_id):
+        data={}
+        sql = """ select aj.name,absl.amount as amt from account_bank_statement as abs
+                        LEFT JOIN account_bank_statement_line as absl ON abs.id = absl.statement_id
+                        LEFT JOIN account_journal as aj ON aj.id = abs.journal_id
+                        WHERE absl.pos_statement_id =%d"""%(order_id)
+        self.cr.execute(sql)
+        data = self.cr.dictfetchall()
+        return data
+
+
+
+report_sxw.report_sxw('report.coup_de_pouce_velo.receipt', 'pos.order', 'addons/coup_de_pouce_velo/report/pos_receipt_coup_de_pouce_velo.rml', parser=order, header=False)
diff --git a/report/pos_receipt_coup_de_pouce_velo.rml b/report/pos_receipt_coup_de_pouce_velo.rml
new file mode 100644 (file)
index 0000000..5dc1792
--- /dev/null
@@ -0,0 +1,181 @@
+<?xml version="1.0"?>
+<document filename="test.pdf">
+  <template pageSize="(204.0,842.0)" title="Receipt" author="OpenERP S.A. (sales@openerp.com)" allowSplitting="20">
+    <pageTemplate id="first">
+      <frame id="first" x1="0.0" y1="0.0" width="204" height="800"/>
+    </pageTemplate>
+  </template>
+  <stylesheet>
+    <blockTableStyle id="Standard_Outline">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table3">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="0,1" stop="0,1"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="1,1" stop="1,1"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="2,1" stop="2,1"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table2">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="1,0" stop="1,0"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table4">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+    </blockTableStyle>
+    <blockTableStyle id="Table10">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="0,1" stop="0,1"/>
+      <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="1,1" stop="1,1"/>
+      <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,-1" stop="1,-1"/>
+      <lineStyle kind="LINEABOVE" colorName="#000000" start="2,1" stop="2,1"/>
+      <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="2,-1" stop="2,-1"/>
+    </blockTableStyle>
+    <initialize>
+      <paraStyle name="all" alignment="justify"/>
+    </initialize>
+    <paraStyle name="P1" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT"/>
+    <paraStyle name="P2" fontName="Helvetica" fontSize="8.0" leading="10"/>
+    <paraStyle name="P3" fontName="Helvetica" fontSize="7.0" leading="9" alignment="LEFT"/>
+    <paraStyle name="P8" fontName="Helvetica" fontSize="9.0" leading="11" alignment="RIGHT"/>
+    <paraStyle name="Standard" fontName="Helvetica"/>
+    <paraStyle name="Text body" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/>
+    <paraStyle name="List" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="Table Contents" fontName="Helvetica"/>
+    <paraStyle name="Table Heading" fontName="Helvetica" alignment="CENTER"/>
+    <paraStyle name="Caption" fontName="Helvetica" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="Index" fontName="Helvetica"/>
+    <paraStyle name="Frame contents" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_default_Centre_9" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER"/>
+    <paraStyle name="terp_default_8" rightIndent="0.0" leftIndent="0.0" fontName="Courier" fontSize="10.0" leading="13" alignment="LEFT"/>
+    <paraStyle name="terp_header_Centre" fontName="Courier-Bold" fontSize="12.0" leading="15" alignment="CENTER"/>
+    <paraStyle name="terp_default_9b" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT"/>
+    <paraStyle name="terp_default_Right_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="RIGHT"/>
+    <paraStyle name="terp_default_Bold_9_Right1" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="RIGHT"/>
+    <paraStyle name="terp_default_Bold_9_Right2" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="RIGHT"/>
+    <paraStyle name="P4" fontName="Courier-Bold" fontSize="10.0" leading="13" alignment="CENTER"/>
+    <paraStyle name="P5" fontName="Courier-Bold" fontSize="10.0" leading="13" alignment="LEFT"/>
+    <paraStyle name="P7" fontName="Courier-Bold" fontSize="10.0" leading="13" alignment="RIGHT"/>
+    <paraStyle name="P6a" fontName="Helvetica" fontSize="10.0" leading="13" alignment="RIGHT"/>
+    <paraStyle name="P7a" fontName="Courier" fontSize="10.0" leading="13" alignment="RIGHT"/>
+    <paraStyle name="P6" rightIndent="0.0" leftIndent="0.0" fontName="Helvetica-Bold" fontSize="10.0" leading="13" alignment="RIGHT"/>
+    <paraStyle name="P13" fontName="Courier-Bold" fontSize="10.0" leading="13" alignment="RIGHT"/>
+    <paraStyle name="Table" fontName="Helvetica" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
+    <images/>
+  </stylesheet>
+  <story>
+    <para style="terp_default_8">[[ repeatIn(objects,'o') ]]</para>
+    <para style="P5">Entretien vélo dans le cadre du"Coup de pouce Vélo - Réparation"</para>
+    <para style="P4">
+      <font color="white"> </font>
+    </para>
+    <para style="terp_header_Centre">[[o.user_id.company_id.name]]</para>
+    <para style="terp_default_Centre_9">[[ address and display_address(address)]]</para>
+    <para style="terp_default_Centre_9">Tél : [[ address and address.phone ]]</para>
+    <para style="terp_default_Centre_9">SIRET : [[o.user_id.company_id.siret]]</para>
+    <para style="terp_default_Centre_9">Atelier : [[ o.shop_id.name ]]</para>
+    <para style="terp_default_Centre_9">Date : [[ o.date_order ]]</para>
+    <para style="P4">
+      <font color="white"> </font>
+    </para>
+    <para style="terp_header_Centre">Bénéficiaire</para>
+    <para style="terp_default_Centre_9">[[ o.partner_id.name ]]</para>
+    <para style="terp_default_Centre_9">Portable: [[ o.partner_id.mobile ]]</para>
+    <para style="P4">
+      <font color="white"> </font>
+    </para>
+    <para style="P4">
+      <font color="white"> </font>
+    </para>
+    <para style="P4">
+      <font color="white"> </font>
+    </para>
+    <para style="P4">[[ o.name ]]</para>
+    <blockTable colWidths="68.0,68.0,68.0" style="Table3">
+      <tr>
+        <td>
+          <para style="P5">Description</para>
+        </td>
+        <td>
+          <para style="P7">Qté</para>
+        </td>
+        <td>
+          <para style="P7">Prix</para>
+        </td>
+      </tr>
+      <tr>
+        <td>
+          <para style="P1">[[ repeatIn(o.lines,'line') ]]</para>
+          <para style="terp_default_9b">[[ line.product_id.name ]]</para>
+          <para style="terp_default_Right_9">
+            <font face="Helvetica">With a [[ line and line.discount == 0.0 and removeParentNode('font') ]] ([[ '%.2f' % line.discount ]]) % discount.</font>
+          </para>
+          <para style="terp_default_9b">
+            <font color="white"> </font>
+          </para>
+        </td>
+        <td>
+          <para style="terp_default_Right_9">[[o.state=='cancel' and o.statement_ids and '-' or '']][['%.f' % line.qty ]]</para>
+        </td>
+        <td>
+          <para style="terp_default_Right_9">[[o.state=='cancel' and o.statement_ids and '-' or '']][[ formatLang(net(line.id), currency_obj=company.currency_id) ]] <font face="Helvetica">[[ line and line.discount == 0.0 and removeParentNode('font') ]] ([[ formatLang(line.discount, currency_obj=company.currency_id) ]])</font></para>
+        </td>
+      </tr>
+    </blockTable>
+    <blockTable colWidths="136.0,68.0" style="Table2">
+      <tr>
+        <td>
+          <para style="P6a">Taxes :</para>
+        </td>
+        <td>
+          <para style="terp_default_Right_9">[[o.state=='cancel' and o.statement_ids and '-' or '']][[formatLang(o.amount_tax, currency_obj=company.currency_id)]]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <blockTable colWidths="136.0,68.0" style="Table4">
+      <tr>
+        <td>
+          <para style="P6">Total :</para>
+        </td>
+        <td>
+          <para style="terp_default_Bold_9_Right2">[[o.state=='cancel' and o.statement_ids and '-' or '']][[formatLang(o.amount_total, currency_obj=company.currency_id)]]</para>
+        </td>
+      </tr>
+    </blockTable>
+    <blockTable colWidths="102.0,34.0,68.0" style="Table10">
+      <tr>
+        <td>
+          <para style="P5">Moyen(s) de paiement</para>
+        </td>
+        <td>
+          <para style="P1">
+            <font color="white"> </font>
+          </para>
+        </td>
+        <td>
+          <para style="P13">Montant</para>
+        </td>
+      </tr>
+      <tr>
+        <td>
+          <para style="P1">[[ repeatIn(get_journal_amt(o),'d') ]]</para>
+          <para style="P2">[[ d['name'] ]]</para>
+        </td>
+        <td>
+          <para style="P1">
+            <font color="white"> </font>
+          </para>
+        </td>
+        <td>
+          <para style="P8">[[ formatLang(d['amt'] or 0, currency_obj=company.currency_id) ]]</para>
+        </td>
+      </tr>
+    </blockTable>
+  </story>
+</document>
index e4bff73..944ec2d 100644 (file)
@@ -15,5 +15,15 @@ class pos_receipt(orm.Model):
         order_obj = self.pool.get('pos.order')
         order = order_obj.browse(cr, uid, order_id, context=context)
         partner_id = order.partner_id.id
-        order_obj.check_partner_mobile(cr, uid, partner_id, context=None)
-        return super(pos_receipt, self).print_report(cr, uid, ids, context=context)
+        if context is None:
+            context = {}
+        datas = {'ids': context.get('active_ids', [])}
+        report_name = 'bikecoop_l10n_fr.receipt'
+        if order.is_cpv:
+            order_obj.check_partner_mobile(cr, uid, partner_id, context=None)
+            report_name = 'coup_de_pouce_velo.receipt'
+        return {
+            'type': 'ir.actions.report.xml',
+            'report_name': report_name,
+            'datas': datas,
+        }