From f5205bf7accb2d659e3f8aaa63c3a11bb9642906 Mon Sep 17 00:00:00 2001 From: Najlaa Date: Wed, 29 Oct 2008 13:13:38 +0100 Subject: [PATCH] invoice intrastat bzr revid: nel@silver-20081029121338-mnwprra0q39n163o --- addons/report_intrastat/intrastat_report.xml | 13 + addons/report_intrastat/report/__init__.py | 1 + addons/report_intrastat/report/invoice.py | 159 +++++ addons/report_intrastat/report/invoice.rml | 593 +++++++++++++++++++ 4 files changed, 766 insertions(+) create mode 100644 addons/report_intrastat/intrastat_report.xml create mode 100644 addons/report_intrastat/report/__init__.py create mode 100644 addons/report_intrastat/report/invoice.py create mode 100644 addons/report_intrastat/report/invoice.rml diff --git a/addons/report_intrastat/intrastat_report.xml b/addons/report_intrastat/intrastat_report.xml new file mode 100644 index 00000000000..fd786d8f04a --- /dev/null +++ b/addons/report_intrastat/intrastat_report.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/addons/report_intrastat/report/__init__.py b/addons/report_intrastat/report/__init__.py new file mode 100644 index 00000000000..837fe6e1ab3 --- /dev/null +++ b/addons/report_intrastat/report/__init__.py @@ -0,0 +1 @@ +import invoice diff --git a/addons/report_intrastat/report/invoice.py b/addons/report_intrastat/report/invoice.py new file mode 100644 index 00000000000..32977b2ed32 --- /dev/null +++ b/addons/report_intrastat/report/invoice.py @@ -0,0 +1,159 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import time +from report import report_sxw +import pooler + +class account_invoice_intrastat(report_sxw.rml_parse): + def __init__(self, cr, uid, name, context): + super(account_invoice_intrastat, self).__init__(cr, uid, name, context) + self.total=0 + self.localcontext.update({ + 'time': time, + 'get_tax_code':self._get_tax_code, + 'get_tax_note':self._get_tax_note, + 'get_origin':self._get_origin, + 'get_line_by_origin':self._get_line_by_origin, + #'gross_weight' : self._gross_weight, + 'total_weight' : self._total_weight, + 'get_incoterm':self._get_incoterm, + 'get_ref':self._get_ref, + 'get_product_code': self._get_product_code, + 'get_product_name': self._get_product_name, + }) + + def _get_origin(self,invoice_id): + self.cr.execute("select distinct origin from account_invoice_line where invoice_id=%d" % (invoice_id)) + res = self.cr.fetchall() or [] + res=map(lambda x:x[0],res) + if not len(res): + res.append('-1') + return res + + + def _get_line_by_origin(self,origin,invoice_id,lang='en_US'): + line_obj=self.pool.get('account.invoice.line') + if not origin and origin!='-1': + invoice_line_ids=line_obj.search(self.cr,self.uid,[('invoice_id','=',invoice_id),('origin','=',False)]) + else: + invoice_line_ids = line_obj.search(self.cr,self.uid,[('invoice_id','=',invoice_id),('origin','=',origin)]) + res= line_obj.browse(self.cr,self.uid,invoice_line_ids,context={'lang':lang}) + return res + + def _get_ref(self,invoice): + if invoice.type in ('out_invoice','out_refund'): + if invoice.reference_type in ('customer_ref'): + return invoice.reference + sale_obj=pooler.get_pool(self.cr.dbname).get('sale.order') + sale_ids=sale_obj.search(self.cr,self.uid,[('invoice_ids','=',[invoice.id])]) + sales=sale_obj.browse(self.cr,self.uid,sale_ids) + if len(sales): + return sales[0].client_order_ref + elif invoice.type in ('in_invoice','in_refund'): + purchase_obj=pooler.get_pool(self.cr.dbname).get('purchase.order') + purchase_ids=purchase_obj.search(self.cr,self.uid,[('invoice_id','=',invoice.id)]) + purchases=purchase_obj.browse(self.cr,self.uid,purchase_ids) + if len(purchases): + return purchases[0].ref + return False + + def _get_tax_code(self, tax_name): + tax_obj=pooler.get_pool(self.cr.dbname).get('account.tax') + ids = tax_obj.search(self.cr, self.uid, [('name','ilike',tax_name)]) + if len(ids) > 0: + tax = tax_obj.browse(self.cr,self.uid,ids)[0] + tax_name=tax.label + return tax_name + def _get_tax_note(self, tax_name,lang): + tax_obj=pooler.get_pool(self.cr.dbname).get('account.tax') + ids = tax_obj.search(self.cr, self.uid, [('name','ilike',tax_name)]) + if len(ids) > 0: + tax = tax_obj.browse(self.cr,self.uid,ids,context={'lang':lang})[0] + tax_note=tax.note + return tax_note + + def _total_weight(self, o): + res = [] + self.cr.execute(""" + select + intrastat_code.name, + sum( + case when uom.category_id != puom.category_id then pt.weight_net * inv_line.quantity + else + case when uom.factor_inv_data > 0 + then + pt.weight_net * inv_line.quantity * uom.factor_inv_data + else + pt.weight_net * inv_line.quantity / uom.factor + end + end + ) as weight + from + report_intrastat_code intrastat_code + left join (product_template pt + left join (product_product pp + left join (account_invoice_line inv_line + left join account_invoice inv on (inv.id=inv_line.invoice_id)) + on (inv_line.product_id=pp.id)) + on (pt.id=pp.product_tmpl_id)) + on (pt.intrastat_id=intrastat_code.id) + left join product_uom uom on uom.id=inv_line.uos_id + left join product_uom puom on puom.id = pt.uom_id + where + inv.id=%d + group by + intrastat_code.name + order by + intrastat_code.name + """%(o.id)) + #self.cr.execute('select r.name, sum(t.weight_net * l.quantity) from report_intrastat_code r, product_template t, product_product p, account_invoice_line l, account_invoice a where r.id = t.intrastat_id and t.id = p.product_tmpl_id and p.id = l.product_id and l.invoice_id = a.id and a.id =%d group by(r.name)' %(o.id)) + res = self.cr.fetchall() or [] + return res + def _get_incoterm(self, code): + print code + incoterm_obj=pooler.get_pool(self.cr.dbname).get('stock.incoterms') + incoterm_ids = incoterm_obj.search(self.cr,self.uid,[('code','=',code)]) + incoterm=incoterm_obj.browse(self.cr,self.uid,incoterm_ids)[0] + return incoterm.code + + def _get_product_code(self, product_id, partner_id): + product_obj=pooler.get_pool(self.cr.dbname).get('product.product') + product = product_obj.browse(self.cr,self.uid, [product_id])[0] + for supinfo in product.seller_ids: + if supinfo.name.id == partner_id: + return ( supinfo.product_code and ("[" + supinfo.product_code + "] ") or '') + supinfo.product_name + return False + + def _get_product_name(self, product_id): + product_obj=pooler.get_pool(self.cr.dbname).get('product.product') + prod_names = product_obj.name_get(self.cr,self.uid,[product_id]) + return prod_names[0][1] + + +report_sxw.report_sxw('report.account.invoice.intrastat', 'account.invoice', 'addons/report_intrastat/report/invoice.rml', parser=account_invoice_intrastat) + diff --git a/addons/report_intrastat/report/invoice.rml b/addons/report_intrastat/report/invoice.rml new file mode 100644 index 00000000000..565a68413e5 --- /dev/null +++ b/addons/report_intrastat/report/invoice.rml @@ -0,0 +1,593 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[ repeatIn(objects,'o') ]] + [[ setLang(o.partner_id.lang) ]][[ setLang(o.partner_id.lang) ]] + + + + + + + + + [[ o.partner_id.title or '' ]] [[ o.partner_id.name ]] + [[ o.address_invoice_id.title or '' ]] [[ o.address_invoice_id.name ]] + [[ o.address_invoice_id.street ]] + [[ o.address_invoice_id.street2 or '' ]] + [[ o.address_invoice_id.zip or '' ]] [[ o.address_invoice_id.city or '' ]] + [[ o.address_invoice_id.state_id and o.address_invoice_id.state_id.name or '' ]] + [[ o.address_invoice_id.country_id and o.address_invoice_id.country_id.name or '' ]] + + + + Tel. : [[ o.address_invoice_id.phone or removeParentNode('para') ]] + Fax : [[ o.address_invoice_id.fax or removeParentNode('para') ]] + VAT : [[ o.partner_id.vat or removeParentNode('para') ]] + + + + Invoice [[ ((o.type == 'out_invoice' and (o.state == 'open' or o.state == 'paid')) or removeParentNode('para')) and '' ]] [[ o.number ]] + PRO-FORMA [[ ((o.type == 'out_invoice' and o.state == 'proforma') or removeParentNode('para')) and '' ]] + Draft Invoice [[ ((o.type == 'out_invoice' and o.state == 'draft') or removeParentNode('para')) and '' ]] + Canceled Invoice [[ ((o.type == 'out_invoice' and o.state == 'cancel') or removeParentNode('para')) and '' ]] + Refund [[ (o.type=='out_refund' or removeParentNode('para')) and '' ]] [[ o.number ]] + Supplier Refund [[ (o.type=='in_refund' or removeParentNode('para')) and '' ]] [[ o.number ]] + Supplier Invoice [[ (o.type=='in_invoice' or removeParentNode('para')) and '' ]] [[ o.number ]] + + + + + + + Document + + + Invoice Date + + + Partner Ref. + + + + + + + [[ o.name ]] + + + [[ o.date_invoice ]] + + + [[ o.address_invoice_id.partner_id.ref or '' ]] + + + + + + + + + + Description + + + Taxes + + + Intrastat + + + Weight + + + Quantity + + + Unit Price + + + Disc. (%) + + + Price + + + +
+ [[ repeatIn(o.invoice_line,'l') ]] + + + + [[ l.name ]] + + + [[ ', '.join([lt.name for lt in l.invoice_line_tax_id]) ]] + + + [[l.product_id and l.product_id.intrastat_id and l.product_id.intrastat_id.name or '']] + + + [[ l.product_id and l.product_id.weight or '']] + + + [[ formatLang(l.quantity) ]] + + + [[ (l.uos_id and l.uos_id.name) or '' ]] + + + [[ formatLang(l.price_unit) ]] + + + [[ l.discount and formatLang (l.discount) or '' ]] + + + [[ formatLang(l.price_subtotal) ]] + + + [[ o.currency_id.code ]] + + + + + [[ format(l.note or removeParentNode('tr')) ]] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + Total (excl. taxes): + + + [[ formatLang(o.amount_untaxed) ]] + + + [[ o.currency_id.code ]] + + + + + + + + + + Taxes: + + + [[ formatLang(o.amount_tax) ]] + + + [[ o.currency_id.code ]] + + + + + + + + + + Total (inclu. taxes): + + + [[ formatLang(o.amount_total) ]] + + + [[ o.currency_id.code ]] + + + + + + + + + + [[ format(o.amount_tax or removeParentNode('blockTable')) ]] + + + + Tax + + + Base + + + Amount + + + + + + + + + + + [[ repeatIn(o.tax_line,'t') ]] + + + + [[ t.name ]] + + + [[ formatLang(t.base) ]] + + + [[ formatLang(t.amount) or 0.00 ]] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[ format(o.comment or removeParentNode('blockTable')) ]] + + + + + + + + + + [[ format((o.payment_term and o.payment_term.note) or removeParentNode('blockTable')) ]] + + + + + + + + + + + + +
+