From: Ludovic CHEVALIER Date: Wed, 27 May 2020 10:27:56 +0000 (+0200) Subject: [PYTHON][VIEW][REPORT] +print custom report when order is cpv X-Git-Url: https://git.cyclocoop.org/?p=burette%2Fcoup_de_pouce_velo.git;a=commitdiff_plain;h=c14f1be0bd82e06a986e9a00d932bc3da3304857 [PYTHON][VIEW][REPORT] +print custom report when order is cpv --- diff --git a/__init__.py b/__init__.py index ca6fde1..5b2378b 100644 --- a/__init__.py +++ b/__init__.py @@ -2,4 +2,5 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import point_of_sale +import report import wizard diff --git a/__openerp__.py b/__openerp__.py index eb16b6d..34bb296 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -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 index f004672..0000000 --- a/data/ir_values.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - note - default - is_cpv=true - pos.order - "Entretien vélo dans le cadre du «Coup de pouce Vélo - Autoréparation»" - - - diff --git a/i18n/coup_de_pouce_velo.pot b/i18n/coup_de_pouce_velo.pot new file mode 100644 index 0000000..170b4a4 --- /dev/null +++ b/i18n/coup_de_pouce_velo.pot @@ -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 index 0000000..093f605 --- /dev/null +++ b/i18n/fr.po @@ -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 \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 index 0000000..630cf01 --- /dev/null +++ b/report/__init__.py @@ -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 index 0000000..b9e3c2a --- /dev/null +++ b/report/pos_receipt.py @@ -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 index 0000000..5dc1792 --- /dev/null +++ b/report/pos_receipt_coup_de_pouce_velo.rml @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[ repeatIn(objects,'o') ]] + Entretien vélo dans le cadre du"Coup de pouce Vélo - Réparation" + + + + [[o.user_id.company_id.name]] + [[ address and display_address(address)]] + Tél : [[ address and address.phone ]] + SIRET : [[o.user_id.company_id.siret]] + Atelier : [[ o.shop_id.name ]] + Date : [[ o.date_order ]] + + + + Bénéficiaire + [[ o.partner_id.name ]] + Portable: [[ o.partner_id.mobile ]] + + + + + + + + + + [[ o.name ]] + + + + Description + + + Qté + + + Prix + + + + + [[ repeatIn(o.lines,'line') ]] + [[ line.product_id.name ]] + + With a [[ line and line.discount == 0.0 and removeParentNode('font') ]] ([[ '%.2f' % line.discount ]]) % discount. + + + + + + + [[o.state=='cancel' and o.statement_ids and '-' or '']][['%.f' % line.qty ]] + + + [[o.state=='cancel' and o.statement_ids and '-' or '']][[ formatLang(net(line.id), currency_obj=company.currency_id) ]] [[ line and line.discount == 0.0 and removeParentNode('font') ]] ([[ formatLang(line.discount, currency_obj=company.currency_id) ]]) + + + + + + + Taxes : + + + [[o.state=='cancel' and o.statement_ids and '-' or '']][[formatLang(o.amount_tax, currency_obj=company.currency_id)]] + + + + + + + Total : + + + [[o.state=='cancel' and o.statement_ids and '-' or '']][[formatLang(o.amount_total, currency_obj=company.currency_id)]] + + + + + + + Moyen(s) de paiement + + + + + + + + Montant + + + + + [[ repeatIn(get_journal_amt(o),'d') ]] + [[ d['name'] ]] + + + + + + + + [[ formatLang(d['amt'] or 0, currency_obj=company.currency_id) ]] + + + + + diff --git a/wizard/pos_receipt.py b/wizard/pos_receipt.py index e4bff73..944ec2d 100644 --- a/wizard/pos_receipt.py +++ b/wizard/pos_receipt.py @@ -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, + }