Browse Source

misc

master
root 1 year ago
parent
commit
41c458391a
13 changed files with 1014 additions and 38 deletions
  1. +86
    -20
      controllers/kalachakra.py
  2. +21
    -1
      models/account_move.py
  3. +10
    -1
      models/accounting_file.py
  4. +2
    -1
      models/product.py
  5. +4
    -1
      security/ir.model.access.csv
  6. +8
    -0
      static/js/kalachakra.js
  7. +24
    -0
      views/account_portal_templates.xml
  8. +44
    -11
      views/accounting_file.xml
  9. +2
    -2
      views/contactus.xml
  10. +3
    -0
      views/product.xml
  11. +20
    -1
      views/website_event_registration.xml
  12. +1
    -0
      wizard/__init__.py
  13. +789
    -0
      wizard/accounting_file_wizard_cdr.py

+ 86
- 20
controllers/kalachakra.py View File

@ -7,7 +7,7 @@ import logging
from odoo import models, fields, api from odoo import models, fields, api
import werkzeug import werkzeug
from werkzeug.datastructures import OrderedMultiDict from werkzeug.datastructures import OrderedMultiDict
from datetime import datetime,timedelta
from datetime import date,datetime,timedelta
from odoo.tools import format_datetime, format_date, is_html_empty from odoo.tools import format_datetime, format_date, is_html_empty
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError from odoo.exceptions import UserError
@ -27,6 +27,7 @@ from odoo.addons.auth_signup.models.res_users import SignupError
from odoo.addons.auth_signup.controllers.main import AuthSignupHome from odoo.addons.auth_signup.controllers.main import AuthSignupHome
import json import json
from collections import OrderedDict from collections import OrderedDict
from odoo.exceptions import AccessError, MissingError
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
def create_donation(self): def create_donation(self):
@ -133,6 +134,24 @@ class Kalachakra_PortalAccount(CustomerPortal):
}) })
return request.render("account.portal_my_invoices", values) return request.render("account.portal_my_invoices", values)
@http.route(['/my/invoices/<int:invoice_id>'], type='http', auth="public", website=True)
def kalachakra_portal_my_invoice_detail(self, invoice_id, access_token=None, report_type=None, download=False, **kw):
try:
invoice_sudo = self._document_check_access('account.move', invoice_id, access_token)
except (AccessError, MissingError):
return request.redirect('/my')
if report_type in ('html', 'pdf', 'text'):
return self._show_report(model=invoice_sudo, report_type=report_type, report_ref='account.account_invoices', download=download)
values = self._invoice_get_page_view_values(invoice_sudo, access_token, **kw)
acquirers = values.get('acquirers')
if acquirers:
country_id = values.get('partner_id') and values.get('partner_id')[0].country_id.id
values['acq_extra_fees'] = acquirers.get_acquirer_extra_fees(invoice_sudo.amount_residual, invoice_sudo.currency_id, country_id)
return request.render("account.portal_invoice_page", values)
def _prepare_home_portal_values(self, counters): def _prepare_home_portal_values(self, counters):
values = super()._prepare_home_portal_values(counters) values = super()._prepare_home_portal_values(counters)
if 'invoice_count' in counters: if 'invoice_count' in counters:
@ -889,12 +908,44 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
return http.request.render('kalachakra.onthespotpayment') return http.request.render('kalachakra.onthespotpayment')
def active_membership(self,partner):
actives_membership=request.env['kalachakra.membership'].search([('partner_id','=',int(partner.id)),('state','=','done'),('end_date','>=','%s 00:00:00' % fields.Date.today())],order="end_date desc")
if actives_membership:
for m in actives_membership:
return m
else: return False
def has_already_renew_membership(self,partner):
actives_membership=request.env['kalachakra.membership'].search([('partner_id','=',int(partner.id)),('state','=','done'),('end_date','>=','%s 00:00:00' % fields.Date.today())],order='end_date desc')
if actives_membership:
if len(actives_membership)>1:
return True
else:
for m in actives_membership:
#on regarde la date de fin la plus récente
#si la date du jour est antérieur à 40 jours avant cette date on
#autorise pas le renouvellement
today=date.today()
today_date = date(today.year,today.month, today.day)
end_date = date(m.end_date.year,m.end_date.month, m.end_date.day)
diff=end_date-today_date
if diff.days>40:
return True
else : return False
else:
return False
@http.route(['/kalachakra/participation'], type='http', auth='public', website=True, sitemap=False,csrf=False) @http.route(['/kalachakra/participation'], type='http', auth='public', website=True, sitemap=False,csrf=False)
def participation(self,type=None,**post): def participation(self,type=None,**post):
data={} data={}
request.session['kalachakra_transaction']='' request.session['kalachakra_transaction']=''
allow_renew=False
if len(post)>0:
if post.get('renew')=="1": allow_renew=True
if type=='participation': if type=='participation':
res=request.env['event.registration'].sudo().search([('id','=',request.session['res_id'])]) res=request.env['event.registration'].sudo().search([('id','=',request.session['res_id'])])
@ -990,12 +1041,22 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
data['countries']=country data['countries']=country
data['country_id']=int(partner.country_id) data['country_id']=int(partner.country_id)
# if type in ('membership','super_membership'):
# if partner.member_status in ('member','super member') and request.session['kalachakra_transaction']=='membership':
# data={}
# data['email']=partner.email
# return http.request.render('kalachakra.already_member',data)
#demande d'adhésion : on vérifie qu'il n'est pas déjà adhérent si demande d'adhésion
#si déjà adhérent on affiche la date de sa fin d'adhésion actuelle
#et on lui demande s'il veut renouveler son adhésion avec nouvelle date de fin
if partner.member_status in ('member') and request.session['kalachakra_transaction']=='membership':
data2={}
active_membership=self.active_membership(partner)
end_date=active_membership.end_date
data2['end_date']=str(end_date.day)+'/'+str(end_date.month)+'/'+str(end_date.year)
data2['email']=partner.email
if self.has_already_renew_membership(partner):
return http.request.render('kalachakra.already_renew_membership',data2)
else:
if not allow_renew:
return http.request.render('kalachakra.already_member',data2)
# si pas connecté # si pas connecté
else: else:
@ -1117,15 +1178,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
}) })
user.sudo().action_reset_password() user.sudo().action_reset_password()
#demande d'adhésion : on vérifie qu'il n'est pas déjà adhérent si demande d'adhésion
# if partner.member_status in ('member','super member') and request.session['kalachakra_transaction']=='membership':
# data={}
# data['email']=partner.email
# return http.request.render('kalachakra.already_member',data)
data={} data={}
if request.session['kalachakra_transaction']=='donation': if request.session['kalachakra_transaction']=='donation':
data['submit_txt']='Faire un don' data['submit_txt']='Faire un don'
@ -1196,11 +1249,24 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
if request.session['kalachakra_transaction'] in ['membership']: if request.session['kalachakra_transaction'] in ['membership']:
vals={} vals={}
if partner.member_status in ('member'):
if not self.has_already_renew_membership(partner):
active_membership=self.active_membership(partner)
vals['start_date']=active_membership.start_date
vals['end_date']=active_membership.start_date+relativedelta(years=1)
else:
data={}
data['email']=partner.email
return http.request.render('kalachakra.already_renew_membership',data)
else:
vals['start_date']=datetime.now()
vals['end_date']=datetime.now()+relativedelta(years=1)
vals['partner_id']=partner.id vals['partner_id']=partner.id
vals['product_id']=int(post.get('product_id')) vals['product_id']=int(post.get('product_id'))
vals['start_date']=datetime.now()
vals['end_date']=datetime.now()+relativedelta(years=1)
vals['amount']=post.get('amount') vals['amount']=post.get('amount')
membership=request.env['kalachakra.membership'].sudo().create(vals) membership=request.env['kalachakra.membership'].sudo().create(vals)
data['order_id']=membership.id data['order_id']=membership.id


+ 21
- 1
models/account_move.py View File

@ -21,7 +21,8 @@ class AccountMove(models.Model):
date_compta_out_refund=fields.Datetime('date import',default=False) date_compta_out_refund=fields.Datetime('date import',default=False)
out_invoice_id=fields.Many2one('account.move' ,ondelete="cascade",domain="[('partner_id','=',partner_id),('move_type','=','out_invoice'),('state','!=','paid')]") out_invoice_id=fields.Many2one('account.move' ,ondelete="cascade",domain="[('partner_id','=',partner_id),('move_type','=','out_invoice'),('state','!=','paid')]")
payment_ids=fields.Many2many('account.payment',compute='_compute_payment_ids') payment_ids=fields.Many2many('account.payment',compute='_compute_payment_ids')
down_payment_paid=fields.Boolean(compute='_compute_down_payment_paid')
is_balance_invoice=fields.Boolean(compute='_compute_is_balance_invoice')
def write(self, data): def write(self, data):
@ -112,6 +113,25 @@ class AccountMove(models.Model):
if r_s[0]==" 'vads_order_id'": if r_s[0]==" 'vads_order_id'":
a.systempay_ref=r_s[1].replace("'","") a.systempay_ref=r_s[1].replace("'","")
break break
def _compute_down_payment_paid(self):
reg=self.env['event.registration'].search([('balance_invoice_id','=',self.id)])
if reg :
if reg.date_payment_down_payment :self.down_payment_paid=True
else :self.down_payment_paid=False
else:
self.down_payment_paid=False
down_payment_paid=True
def _compute_is_balance_invoice(self):
reg=self.env['event.registration'].search([('balance_invoice_id','=',self.id)])
if reg:self.is_balance_invoice=True
else:self.is_balance_invoice=False
def button_event_registration(self): def button_event_registration(self):
reg=self.env['event.registration'].search(['|','|','|',('invoice_id','=',self.id),\ reg=self.env['event.registration'].search(['|','|','|',('invoice_id','=',self.id),\
('down_payment_invoice_id','=',self.id),\ ('down_payment_invoice_id','=',self.id),\


+ 10
- 1
models/accounting_file.py View File

@ -11,4 +11,13 @@ class accounting_file(models.Model):
exported_date=fields.Date(string='Exported Date',tracking=True, readonly=True) exported_date=fields.Date(string='Exported Date',tracking=True, readonly=True)
start_date=fields.Date(string='Start Date',tracking=True, readonly=True) start_date=fields.Date(string='Start Date',tracking=True, readonly=True)
end_date=fields.Date(string='End Date',tracking=True, readonly=True) end_date=fields.Date(string='End Date',tracking=True, readonly=True)
class cdr_accounting_file(models.Model):
_name = 'cdr.accounting.file'
_description = 'Centre de retraite accounting files'
accounting_file = fields.Binary('accounting file', readonly=True)
document_fname=fields.Char(default='undefined')
exported_date=fields.Date(string='Exported Date',tracking=True, readonly=True)
start_date=fields.Date(string='Start Date',tracking=True, readonly=True)
end_date=fields.Date(string='End Date',tracking=True, readonly=True)

+ 2
- 1
models/product.py View File

@ -14,4 +14,5 @@ class KalachakraProductTemplate(models.Model):
booking_option_product = fields.Boolean(string="booking option product", tracking=True) booking_option_product = fields.Boolean(string="booking option product", tracking=True)
price_per=fields.Selection(string="Price per",selection=[('stay','Stay'),('night', 'Night'), ('day', 'Day')], default='stay', tracking=True) price_per=fields.Selection(string="Price per",selection=[('stay','Stay'),('night', 'Night'), ('day', 'Day')], default='stay', tracking=True)
individual_room=fields.Boolean(string="individual room", tracking=True) individual_room=fields.Boolean(string="individual room", tracking=True)
on_website=fields.Boolean(string="On website", tracking=True)
on_website=fields.Boolean(string="On website", tracking=True)
cdr_property_account_income_id=fields.Many2one('account.account',string='Compte de revenus Centre de retraite')

+ 4
- 1
security/ir.model.access.csv View File

@ -31,4 +31,7 @@ access_event_teaching_day_public,event_teaching_day_public,model_event_teaching_
access_event_teaching_day_portal,event_teaching_day_portal,model_event_teaching_day,base.group_portal,1,0,0,0 access_event_teaching_day_portal,event_teaching_day_portal,model_event_teaching_day,base.group_portal,1,0,0,0
access_accounting_file,access to accounting files,model_accounting_file,account.group_account_manager,1,1,1,1 access_accounting_file,access to accounting files,model_accounting_file,account.group_account_manager,1,1,1,1
access_accounting_file_wizard,access to accounting file wizard,model_accounting_file_wizard,account.group_account_manager,1,1,1,1
access_accounting_file_wizard,access to accounting file wizard,model_accounting_file_wizard,account.group_account_manager,1,1,1,1
access_cdr_accounting_file,access to cdr accounting files,model_cdr_accounting_file,account.group_account_manager,1,1,1,1
access_cdr_accounting_file_wizard,access to cdr accounting file wizard,model_cdr_accounting_file_wizard,account.group_account_manager,1,1,1,1

+ 8
- 0
static/js/kalachakra.js View File

@ -134,6 +134,14 @@ odoo.define('kalachakra.main', function (require) {
$( "#form" ).submit(); $( "#form" ).submit();
}); });
$( "#renew_yes" ).click(function() {
$('#renew').val("1");
$( "#form" ).submit();
});
$( "#make_donation_btn" ).click(function() { $( "#make_donation_btn" ).click(function() {
$('#form').attr('action', '/kalachakra/participation?type=donation'); $('#form').attr('action', '/kalachakra/participation?type=donation');


+ 24
- 0
views/account_portal_templates.xml View File

@ -28,4 +28,28 @@
<td class="text-right"><span t-esc="invoice.amount_total" t-options='{"widget": "monetary", "display_currency": invoice.currency_id}'/></td> <td class="text-right"><span t-esc="invoice.amount_total" t-options='{"widget": "monetary", "display_currency": invoice.currency_id}'/></td>
</xpath> </xpath>
</template> </template>
<template id="kalachakra_portal_invoice_page_inherit_payment" name="Payment on My Invoices" inherit_id="account_payment.portal_invoice_page_inherit_payment">
<xpath expr="//a[@data-target='#pay_with']" position="replace">
<a href="#" t-if="invoice.state == 'posted' and invoice.down_payment_paid and invoice.is_balance_invoice and invoice.payment_state in ('not_paid', 'partial') and invoice.amount_total and invoice.move_type == 'out_invoice' and (pending_manual_txs or not tx_ids or invoice.amount_residual)"
class="btn btn-primary btn-block mb-2" data-toggle="modal" data-target="#pay_with">
<i class="fa fa-fw fa-arrow-circle-right"/> Pay Now
</a>
<a href="#" t-if="invoice.state == 'posted' and not invoice.is_balance_invoice and invoice.payment_state in ('not_paid', 'partial') and invoice.amount_total and invoice.move_type == 'out_invoice' and (pending_manual_txs or not tx_ids or invoice.amount_residual)"
class="btn btn-primary btn-block mb-2" data-toggle="modal" data-target="#pay_with">
<i class="fa fa-fw fa-arrow-circle-right"/> Pay Now
</a>
<div t-if="not invoice.down_payment_paid and invoice.is_balance_invoice" class="alert alert-info py-1 mb-2" >
<i class="fa fa-fw fa-check-circle"/> You must pay the down payment before
</div>
</xpath>
</template>
</odoo> </odoo>

+ 44
- 11
views/accounting_file.xml View File

@ -15,16 +15,26 @@
</field> </field>
</record> </record>
<record model="ir.ui.view" id="kalachakra.cdr_accounting_file_list">
<field name="name">CDR kalachakra_accounting file list</field>
<field name="model">cdr.accounting.file</field>
<field name="arch" type="xml">
<tree default_order='create_date desc'>
<field name="create_date"/>
<field name="start_date"/>
<field name="exported_date"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="kalachakra.accounting_file_form"> <record model="ir.ui.view" id="kalachakra.accounting_file_form">
<field name="name">kalachakra_member form</field>
<field name="model">accounting.file</field>
<field name="name">kalachakra_accounting_file form</field>
<field name="model">cdr.accounting.file</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form> <form>
<!-- <header> <button type="object" name="action_create_accounting_file" string="Generate csv export"/>
</header> -->
<sheet> <sheet>
<group> <group>
<field name="create_date"/> <field name="create_date"/>
<field name="create_uid"/> <field name="create_uid"/>
@ -34,16 +44,30 @@
<field name="end_date"/> <field name="end_date"/>
<field name="exported_date"/> <field name="exported_date"/>
</group> </group>
</sheet> </sheet>
</form> </form>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="kalachakra.cdr_accounting_file_form">
<field name="name">CDR kalachakra_accounting_file form</field>
<field name="model">cdr.accounting.file</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="create_date"/>
<field name="create_uid"/>
<field name="accounting_file" filename="document_fname" widget="binary"/>
<field name="document_fname" invisible="1"/>
<field name="start_date"/>
<field name="end_date"/>
<field name="exported_date"/>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="accounting_file_action"> <record model="ir.actions.act_window" id="accounting_file_action">
<field name="name">Accounting files</field> <field name="name">Accounting files</field>
@ -51,10 +75,19 @@
<field name="view_mode">tree,form,pivot</field> <field name="view_mode">tree,form,pivot</field>
</record> </record>
<record model="ir.actions.act_window" id="cdr_accounting_file_action">
<field name="name">CDR accounting files</field>
<field name="res_model">cdr.accounting.file</field>
<field name="view_mode">tree,form,pivot</field>
</record>
<menuitem id="accounting_file_menu" action="accounting_file_action" <menuitem id="accounting_file_menu" action="accounting_file_action"
parent="account.menu_finance_entries_accounting_miscellaneous" sequence="10"/> parent="account.menu_finance_entries_accounting_miscellaneous" sequence="10"/>
<menuitem id="cdr_accounting_file_menu" action="cdr_accounting_file_action"
parent="account.menu_finance_entries_accounting_miscellaneous" sequence="11"/>
</data> </data>
</odoo> </odoo>

+ 2
- 2
views/contactus.xml View File

@ -2,7 +2,7 @@
<odoo> <odoo>
<template id="kalachakra.contactus" name="contact us"> <template id="kalachakra.contactus" name="contact us">
<t t-call="website.layout">
<div class="oe_structure"> <div class="oe_structure">
<div class="container"> <div class="container">
<h1>coucou</h1> <h1>coucou</h1>
@ -14,7 +14,7 @@
<iframe width="700" height="440" src="https://maps.google.com/maps?width=700&amp;height=440&amp;hl=en&amp;q=5%20passage%20delessert%2075010%20paris+(Titre)&amp;ie=UTF8&amp;t=&amp;z=13&amp;iwloc=B&amp;output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe><div style="position: absolute;width: 80%;bottom: 10px;left: 0;right: 0;margin-left: auto;margin-right: auto;color: #000;text-align: center;"> <iframe width="700" height="440" src="https://maps.google.com/maps?width=700&amp;height=440&amp;hl=en&amp;q=5%20passage%20delessert%2075010%20paris+(Titre)&amp;ie=UTF8&amp;t=&amp;z=13&amp;iwloc=B&amp;output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe><div style="position: absolute;width: 80%;bottom: 10px;left: 0;right: 0;margin-left: auto;margin-right: auto;color: #000;text-align: center;">
</div><style>#gmap_canvass img{max-width:none!important;background:none!important}</style></div> </div><style>#gmap_canvass img{max-width:none!important;background:none!important}</style></div>
</t>
</template> </template>


+ 3
- 0
views/product.xml View File

@ -22,6 +22,9 @@
</group> </group>
</div> </div>
<xpath expr="//field[@name='property_account_income_id']" position="after">
<field name="cdr_property_account_income_id"/>
</xpath>
</field> </field>
</record> </record>


+ 20
- 1
views/website_event_registration.xml View File

@ -301,15 +301,34 @@
<t t-call="website.layout"> <t t-call="website.layout">
<form id="form" action="/kalachakra/participation?type=membership" method="post" data-success_page="/participation?type=membership" >
<input type="hidden" name="renew" id="renew" value="0"/>
<div class="container-fluid"> <div class="container-fluid">
<h6>You are already a member with this email adress : <span t-esc="email"/></h6> <h6>You are already a member with this email adress : <span t-esc="email"/></h6>
<h6>and the end date is :<span t-esc="end_date"/></h6>
<h6>Do you want to renew it for one more year ?</h6>
<button type="submit" id='renew_yes' class="ml-4 btn btn-secondary">yes</button>
<a href="/" class="ml-4 btn btn-secondary">no</a>
</div>
</form>
</t>
</template>
<template id="kalachakra.already_renew_membership" name="alreadyrenewmembership">
<t t-call="website.layout">
<div class="container-fluid">
<h6>You have already renew your membership, and the date end is : <span t-esc="end_date"/></h6>
<a href="/" class="ml-4 btn btn-secondary">back Home</a> <a href="/" class="ml-4 btn btn-secondary">back Home</a>
</div> </div>
</t> </t>
</template> </template>
<template id="kalachakra.registration_contactform" name="Form"> <template id="kalachakra.registration_contactform" name="Form">
<t t-call="website.layout"> <t t-call="website.layout">


+ 1
- 0
wizard/__init__.py View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import accounting_file_wizard from . import accounting_file_wizard
from . import accounting_file_wizard_cdr

+ 789
- 0
wizard/accounting_file_wizard_cdr.py View File

@ -0,0 +1,789 @@
from odoo import fields, models,api,_
from odoo.exceptions import UserError, ValidationError, Warning
from datetime import datetime,date
import os,secrets
import decimal
import base64
import logging
import json
_logger = logging.getLogger(__name__)
code_journal='IN'
date_compta=fields.datetime.now()
total_debit=total_credit=0
no_mvt=1
class CdrAccountingFileWizard(models.TransientModel):
_name = 'cdr.accounting.file.wizard'
_description = 'Centre de retraite accounting file wizard'
start_date=fields.Datetime('start date',required=True,default=lambda self: self._compute_start_date())
end_date=fields.Datetime('end date',required=True,default=lambda self: self._compute_end_date())
debug_mode=fields.Boolean('debug mode',default=True)
export_donation_lines=fields.Boolean('export donation lines',default=True)
export_booking_event_lines=fields.Boolean('export_booking_event_lines',default=True)
export_out_refund_lines=fields.Boolean('export_out_refund_lines',default=True)
export_end_of_stay_lines=fields.Boolean('export_end_of_stay_lines',default=True)
def _compute_end_date(self):
date_today=fields.Date.context_today(self)
return date_today
def _compute_start_date(self):
date_today=fields.Date.context_today(self)
return datetime(date_today.year,date_today.month,1)
def action_create_accounting_file(self):
global total_debit
global total_credit
total_debit=0
total_credit=0
tmstp=secrets.token_hex(16)
filename='/tmp/accounting_file_'+tmstp+'.csv'
f = open(filename, "a",encoding="cp1252")
#N° mouvement 1-5
#Code du journal "IN" 6-7
#Date 8-17 (10 cars) ex:01/04/2022
#N° de compte 18-23 (6 cars)
#Libellé 24- (12+ 13 cars) 12:Initial prénom+nom 13:lib evt exemple :E Meurinne Besoins cent
#Débit ex: 200,00
#Crédit ex : 200,00
#N° de pièce: ref transaction , ex: txD-457
fic_line='"N° mouvement;Code du journal;Date;N° de compte;Libellé;Débit;Crédit;N° de pièce'+'"'+"\n"
#fic_line=fic_line.encode(encoding="cp1252",errors='ignore')
f.write(fic_line)
if self.export_donation_lines:self.donation_lines(f)
if self.export_booking_event_lines:self.booking_event_lines(f)
if self.export_out_refund_lines:self.out_refund_lines(f)
if self.export_end_of_stay_lines:self.end_of_stay_lines(f)
fic_line="TOTAL_DEBIT="+str(total_debit)+ " TOTAL CREDIT="+str(total_credit)
#fic_line=fic_line.encode(encoding="cp1252",errors='ignore')
f.write(fic_line)
f.close
f = open(filename, "rb")
data = f.read()
#raise UserError('gg'+f.read())
vals={}
vals['accounting_file']=base64.encodebytes(data)
vals['document_fname']='export_comptable.csv'
vals['exported_date']=fields.Date.context_today(self)
vals['start_date']=self.start_date
vals['end_date']=self.end_date
res=self.env['accounting.file'].create(vals)
f.close
os.unlink(filename)
#display account deposit
return {
'name': 'Account deposit form',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'accounting.file',
'res_id': int(res.id),
'type': 'ir.actions.act_window',
'target': 'current'
}
def _accounting_line(self,no_mvt,date_line,account_number,lib,debit,credit,lib_piece):
str_line='"'+str(no_mvt)+';'+'IN'+';'+str(date_line)+';'+str(account_number)+';'+str(lib)+';'+str(debit)+';'+str(credit)+';'+str(lib_piece)+'"'+'\n'
return str_line
def donation_lines(self,f):
global total_debit
global total_credit
global no_mvt
#écritures pour les dons validés (donc payés), non déjà exportés
donation=self.env['donation.donation'].search([('date_compta','=',False),('state','=','done')])
#raise UserError(donation)
for d in donation:
date_payment=d.donation_date
#recherche de la date de paiement du don
trans=self.env['payment.transaction'].search([('donation_ids','in',d.id),('state','=','done')],limit=1)
if trans : date_payment=trans.date.date()
#if datetime(d.donation_date.year, d.donation_date.month, d.donation_date.day)<self.start_date:continue
if date_payment<self.start_date.date():continue
if date_payment>self.end_date.date():continue
date_payment=self._date_format(date_payment)
#on ne prend pas en compte les dons liés à une retraite
#car traité avec les retraites
if d.invoice_id: continue
if not self.debug_mode: d.date_compta=date_compta
#if not d.payment_mode_id: raise UserError(_("no payment mode found for donation %r ",donation.number))
#if not d.payment_mode_id.fixed_journal_id: raise UserError(_("no account found for payment mode %r",d.payment_mode_id.name))
account_debit_number=self._file_format(str(d.payment_mode_id.fixed_journal_id.default_account_id.code),6)
if d.transaction_id.acquirer_id.name=='Paypal':
account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','Paypal')]).fixed_journal_id.default_account_id.code),6)
firstname=d.partner_id.firstname
name=d.partner_id.name
if not name : name='N/A'
if not firstname: firstname=' '
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
#lib1=lib1[11]
date_line=self._date_format(d.donation_date)
if trans : date_line=self._date_format(str(trans.date.year)+'-'+str(trans.date.month)+'-'+str(trans.date.day))
#recherche de la transaction
lib_piece=self._file_format(d.number,20)
pt=self.env['payment.transaction'].search([('donation_ids','in',d.id)],limit=1)
if pt: lib_piece=pt.reference
for line in d.line_ids:
affectation=line.product_id.name
amount=line.amount
#if not line.product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",line.product_id.name))
account_credit_number=self._file_format(line.product_id.property_account_income_id.code,6)
break
#credit line
lib2=self._file_format(affectation,13)
lib=lib1+' '+lib2
debit=''
credit=str(amount)
total_credit+=amount
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt+=1
#debit line
debit=str(amount)
credit=''
account_number=account_debit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
total_debit+=amount
no_mvt+=1
return no_mvt
def end_of_stay_lines(self,f):
global total_debit
global total_credit
global no_mvt
registration=self.env['event.registration'].search([])
for reg in registration:
if not reg.end_of_stay_invoice_id:continue
if reg.end_of_stay_invoice_id.date_compta_end_of_stay:continue
if not reg.date_payment_end_of_stay:continue
if reg.date_payment_end_of_stay and reg.date_payment_end_of_stay<self.start_date.date(): continue
if reg.date_payment_end_of_stay and reg.date_payment_end_of_stay>self.end_date.date(): continue
account_debit_number=self._file_format(str(reg.end_of_stay_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6)
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.end_of_stay_invoice_id.id),('state','=','done')],limit=1)
if trans and trans.acquirer_id.name=='Paypal':
account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','Paypal')]).fixed_journal_id.default_account_id.code),6)
if trans and trans.acquirer_id.name=='Paiement par carte bancaire':
account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','CB')]).fixed_journal_id.default_account_id.code),6)
account_credit_number=self._file_format('170000',6)
firstname=reg.partner_id.firstname
name=reg.partner_id.name
if not name : name='N/A'
if not firstname: firstname=' '
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
lib2=self._file_format(reg.event_id.booking_product_id.name,13)
lib=lib1+' '+lib2
#recherche de l'adhésion
membership_credit_line=False
membership=self.env['kalachakra.membership'].search([('invoice_id','=',int(reg.end_of_stay_invoice_id.id))])
membership_amount=0
if membership:
membership_credit_line=True
membership_amount=membership.amount
#recherche de dons
donation_credit_line=False
donation_amount=0
donations=donation_booking=self.env['donation.donation'].search([('invoice_id','=',int(reg.end_of_stay_invoice_id.id))])
if donations:
donation_credit_line=True
for d in donations:
donation_amount+=d.amount_total
date_line=self._payment_date(reg.end_of_stay_invoice_id)
#écriture de débit
if not self.debug_mode: reg.date_compta_end_of_stay=date_compta
amount=reg.end_of_stay_invoice_id.amount_total
if amount==0: continue
debit=str(amount)
credit=''
lib_piece=self._file_format(reg.end_of_stay_invoice_id.name,20)
account_number=account_debit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt+=1
total_debit+=amount
#écriture de crédit
debit=''
credit=str(amount-membership_amount-donation_amount)
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt+=1
total_credit+=amount
if membership_credit_line:
debit=''
credit=str(membership_amount)
account_number=self._file_format('756100',6)
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_credit+=membership_amount
if donation_credit_line:
for d in donations :
debit=''
amount=d.amount_total
credit=str(amount)
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_credit+=amount
def booking_event_lines(self,f):
global total_debit
global total_credit
global no_mvt
#écritures pour les inscription aux RETRAITES avec facture acomptes payés + factures soldes payés non déjà exporté
registration=self.env['event.registration'].search([])
membership_amount=0
donation_amount=0
membership_credit_line=False
donation_credit_line=False
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
account_credit_number=self._file_format('170000',6)
for reg in registration:
if reg.event_id.booking_event:
#si pas de facture d'acompte et facture payée:
if reg.invoice_id.amount_total>0 and reg.invoice_id.payment_state=='paid' and reg.date_compta==False :
if reg.date_payment and reg.date_payment<self.start_date.date(): continue
if reg.date_payment and reg.date_payment>self.end_date.date(): continue
self.booking_invoice_lines(f,reg)
#si facture d'acompte payée et pas encore exporté
if reg.down_payment_invoice_id.payment_state=='paid' and not reg.date_compta_down_payment:
if reg.date_payment_down_payment and reg.date_payment_down_payment>=self.start_date.date():
self.booking_down_payment_invoice_lines(f,reg)
#si solde payée pas exporté :
if reg.balance_invoice_id.payment_state=='paid' and not reg.date_compta:
if reg.date_payment_balance and reg.date_payment_balance>=self.start_date.date():
self.booking_balance_invoice_lines(f,reg)
_logger.error('TOTAL DEBIT '+str(total_debit)+' TOTAL CREDIT '+str(total_credit))
return True
def booking_balance_invoice_lines(self,f,reg) :
global total_debit
global total_credit
global no_mvt
membership_amount=0
donation_amount=0
membership_credit_line=False
donation_credit_line=False
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
account_credit_number=self._file_format('170000',6)
firstname=reg.partner_id.firstname
name=reg.partner_id.name
if not name : name='N/A'
if not firstname: firstname=' '
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
lib2=self._file_format(reg.event_id.booking_product_id.name,13)
lib=lib1+' '+lib2
if not self.debug_mode: reg.date_compta=date_compta
down_payment=False
balance_payment=True
account_debit_number=''
for p in reg.balance_invoice_id.payment_ids:
account_debit_number=self._file_format(str(self.env['account.journal'].search([('id','=',int(p.journal_id))]).default_account_id.code),6)
break
date_line=self._payment_date(reg.balance_invoice_id)
#recherche de l'adhésion
membership_credit_line=False
membership=self.env['kalachakra.membership'].search([('date_compta','=',False),('balance_invoice_id','=',int(reg.balance_invoice_id))])
if membership:
membership_credit_line=True
membership_amount=membership.amount
#recherche de dons
donation_credit_line=False
donations=donation_booking=self.env['donation.donation'].search([('date_compta','=',False),('invoice_id','=',int(reg.balance_invoice_id))])
if donations:
donation_credit_line=True
for d in donations:
donation_amount+=donations.amount_total
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.balance_invoice_id.id)],limit=1)
if trans:
lib_piece=self._file_format(trans.reference,20)
else:
lib_piece=self._file_format(reg.balance_invoice_id.name,20)
amount=reg.balance_invoice_id.amount_total
if amount==0: return False
credit=''
debit=str(amount)
account_number=account_debit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_debit+=amount
if not amount: amount=0
amount=reg.balance_invoice_id.amount_total-membership_amount-donation_amount
debit=''
credit=str(amount)
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_credit+=amount
if membership_credit_line:
debit=''
credit=str(membership_amount)
account_number=self._file_format('756100',6)
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_credit+=membership_amount
if donation_credit_line:
for d in donations :
debit=''
amount=d.amount_total
credit=str(amount)
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_credit+=amount
def booking_down_payment_invoice_lines(self,f,reg):
global total_debit
global total_credit
global no_mvt
membership_amount=0
donation_amount=0
membership_credit_line=False
donation_credit_line=False
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
account_credit_number=self._file_format('170000',6)
firstname=reg.partner_id.firstname
name=reg.partner_id.name
if not name : name='N/A'
if not firstname: firstname=' '
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
lib2=self._file_format(reg.event_id.booking_product_id.name,13)
lib=lib1+' '+lib2
if not self.debug_mode: reg.date_compta_down_payment=date_compta
down_payment=True
balance_payment=False
donation_credit_line=False
membership_credit_line=False
account_debit_number=self._file_format(str(reg.down_payment_invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6)
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.down_payment_invoice_id.id),('state','=','done')],limit=1)
if trans and trans.acquirer_id.name=='Paypal': account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','Paypal')]).fixed_journal_id.default_account_id.code),6)
if trans and trans.acquirer_id.name=='Paiement par carte bancaire': account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','CB')]).fixed_journal_id.default_account_id.code),6)
amount=reg.down_payment_invoice_id.amount_total
date_line=self._date_format(reg.date_payment_down_payment)
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.down_payment_invoice_id.id)],limit=1)
if trans:
lib_piece=self._file_format(trans.reference,20)
else:
lib_piece=self._file_format(reg.down_payment_invoice_id.name,20)
amount=reg.down_payment_invoice_id.amount_total
if amount==0: return False
credit=''
debit=str(amount)
account_number=account_debit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_debit+=amount
#credit(s) line(s)
#participation credit line
if not amount: amount=0
amount=reg.down_payment_invoice_id.amount_total
debit=''
credit=str(amount)
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_credit+=amount
def booking_invoice_lines(self,f,reg):
global total_debit
global total_credit
global no_mvt
#_logger.error('acompte:'+str(reg.down_payment_invoice_id.payment_state)+' solde :'+str(reg.balance_invoice_id.payment_state)+' date_compta'+str(reg.date_compta)+' date_compta_down_payment:'+str(reg.date_compta_down_payment))
membership_amount=0
donation_amount=0
membership_credit_line=False
donation_credit_line=False
#if not reg.event_id.participation_product_id.property_account_income_id: raise UserError(_("no credit account found for product %r",reg.event_id.participation_product_id.name))
account_credit_number=self._file_format('170000',6)
firstname=reg.partner_id.firstname
name=reg.partner_id.name
if not name : name='N/A'
if not firstname: firstname=' '
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
lib2=self._file_format(reg.event_id.booking_product_id.name,13)
lib=lib1+' '+lib2
if not self.debug_mode: reg.date_compta=date_compta
case_line=1
down_payment=False
balance_payment=False
#if not reg.invoice_id.payment_mode_id.fixed_journal_id: raise UserError(_("no account found payment mode %r",reg.invoice_id.payment_mode_id.name))
account_debit_number=self._file_format(str(reg.invoice_id.payment_mode_id.fixed_journal_id.default_account_id.code),6)
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.invoice_id.id),('state','=','done')],limit=1)
if trans and trans.acquirer_id.name=='Paypal':
account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','Paypal')]).fixed_journal_id.default_account_id.code),6)
if trans and trans.acquirer_id.name=='Paiement par carte bancaire':
account_debit_number=self._file_format(str(self.env['account.payment.mode'].search([('name','=','CB')]).fixed_journal_id.default_account_id.code),6)
#recherche de l'adhésion
membership_credit_line=False
membership=self.env['kalachakra.membership'].search([('invoice_id','=',int(reg.invoice_id))])
if membership:
membership_credit_line=True
membership_amount=membership.amount
#recherche de dons
donation_credit_line=False
donations=donation_booking=self.env['donation.donation'].search([('invoice_id','=',int(reg.invoice_id))])
if donations:
donation_credit_line=True
for d in donations:
donation_amount+=d.amount_total
date_line=self._date_format(reg.date_payment)
trans=self.env['payment.transaction'].search([('state','=','done'),('invoice_ids','in',reg.invoice_id.id)],limit=1)
if trans:
lib_piece=self._file_format(trans.reference,20)
else:
lib_piece=self._file_format(reg.invoice_id.name,20)
#debit line
amount=reg.invoice_id.amount_total
if amount==0: return False
credit=''
debit=str(amount)
account_number=account_debit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_debit+=amount
#credit(s) line(s)
#participation credit line
if not amount: amount=0
amount=amount-membership_amount-donation_amount
debit=''
credit=str(amount)
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_credit+=amount
if membership_credit_line:
debit=''
credit=str(membership_amount)
account_number=self._file_format('756100',6)
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_credit+=membership_amount
if donation_credit_line:
for d in donations :
debit=''
amount=d.amount_total
credit=str(amount)
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt=no_mvt+1
total_credit+=amount
def out_refund_lines(self,f):
global total_debit
global total_credit
global no_mvt
#écritures pour les avoirs pas encore utilisés ou payés mais jamais passé en compta
out_refund_invoices=self.env['account.move'].search([('move_type','=','out_refund'),('state','=','posted'),('payment_state','=','not_paid'),('date_compta','=',False),('date_compta_out_refund','=',False)])
for invoice in out_refund_invoices:
if invoice.invoice_date<self.start_date.date(): continue
if invoice.invoice_date>self.end_date.date(): continue
if not self.debug_mode: invoice.date_compta_out_refund=date_compta
firstname=invoice.partner_id.firstname
name=invoice.partner_id.name
if not name : name='N/A'
if not firstname: firstname=' '
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
lines=self.env['account.move.line'].search([('move_id','=',int(invoice.id))],limit=1)
if lines:
lib2=self._file_format(lines.name,13)
else:
lib2=''
lib=lib1+' '+lib2
lib_piece=self._file_format(invoice.name,20)
#écriture de débit
amount=invoice.amount_total
account_debit_number='170000'
date_line=self._date_format(invoice.invoice_date)
if amount==0: continue
debit=str(amount)
credit=''
account_number=account_debit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt+=1
total_debit+=amount
#écriture de crédit
debit=''
credit=str(amount)
account_credit_number='170000'
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt+=1
total_credit+=amount
#écritures pour les avoirs qui ont été utilisés
#écriture Débit 411000 – Crédit 170000
out_refund_invoices=self.env['account.move'].search([('move_type','=','out_refund'),('payment_state','=','paid'),('date_compta','=',False)])
for invoice in out_refund_invoices:
#_logger.error(invoice.id)
if not self.debug_mode: invoice.date_compta=date_compta
firstname=invoice.partner_id.firstname
name=invoice.partner_id.name
#_logger.error(name)
if not name : name='N/A'
if not firstname: firstname=' '
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
lib2=''
reg=self.env['event.registration'].search(['|',('invoice_id','=',int(invoice.out_invoice_id)),('balance_invoice_id','=',int(invoice.out_invoice_id))])
if reg:
lib2=self._file_format(reg.event_id.name,13)
else:
lib2=self._file_format(invoice.payment_reference,13)
lib=lib1+' '+lib2
if reg:
lib_piece=self._file_format(invoice.out_invoice_id.name,20)
else :
lib_piece=self._file_format(invoice.name,20)
#écriture de débit
amount=invoice.amount_total
account_debit_number='170000'
#date du paiement
#_logger.error(self._payment_date_ok(invoice.out_invoice_id))
if not self._payment_date_ok(invoice):continue
date_line=self._payment_date(invoice)
if amount==0: continue
debit=str(amount)
credit=''
account_number=account_debit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt+=1
total_debit+=amount
#écriture de crédit
debit=''
credit=str(amount)
if invoice.out_invoice_id:
account_credit_number='170000'
else:
account_credit_number= self._payment_account_number(invoice)
account_number=account_credit_number
fic_line=self._accounting_line(no_mvt,date_line,account_number,lib,debit,credit,lib_piece)
f.write(fic_line)
no_mvt+=1
total_credit+=amount
def _file_format(self,data,nbcars):
if data:
if len(data)>nbcars:
return data[0:nbcars]
else:
return data
else:
return ''
def _payment_(self,move_id):
if move_id.invoice_payments_widget:
payment_info=json.loads(move_id.invoice_payments_widget)
if payment_info:
if datetime.strptime(payment_info['content'][0]['date'],'%Y-%m-%d')>self.start_date:
return False
else:
return True
else:return True
def _payment_date_ok(self,move):
if move.invoice_payments_widget:
payment_info=json.loads(move.invoice_payments_widget)
if payment_info:
#_logger.error(payment_info['content'][0]['date'])
if datetime.strptime(payment_info['content'][0]['date'],'%Y-%m-%d')>=self.start_date:
return True
else:
return False
else:
return False
def _payment_date(self,move_id):
if move_id.invoice_payments_widget:
payment_info=json.loads(move_id.invoice_payments_widget)
if payment_info:
return self._date_format(payment_info['content'][0]['date'])
#
else:
return 'False'
else:return 'False'
def _payment_account_number(self,move_id):
if move_id.invoice_payments_widget:
payment_info=json.loads(move_id.invoice_payments_widget)
if payment_info:
account_payment_id=payment_info['content'][0]['account_payment_id']
#payment_mode_id.fixed_journal_id.default_account_id.code
account_number=self.env['account.payment'].search([('id','=',int(account_payment_id))]).journal_id.default_account_id.code
return account_number
else:
return ''
else:return ''
def _date_format(self,data):
#_logger.error('date='+str(data))
if data:
r=str(data).split('-')
if len(r[2])==1:r[2]='0'+r[2]
if len(r[1])==1:r[1]='0'+r[1]
return r[2]+'/'+r[1]+'/'+r[0]
else:
return 'False'

Loading…
Cancel
Save