Browse Source

misc

master
root 2 years ago
parent
commit
5626b3dd0a
23 changed files with 658 additions and 117 deletions
  1. +2
    -1
      __init__.py
  2. +3
    -1
      __manifest__.py
  3. +2
    -1
      controllers/booking.py
  4. +12
    -12
      controllers/kalachakra.py
  5. +1
    -0
      models/__init__.py
  6. +1
    -0
      models/account_move.py
  7. +13
    -0
      models/accounting_file.py
  8. +1
    -0
      models/booking_event_registration.py
  9. +1
    -0
      models/donation.py
  10. +1
    -64
      models/event.py
  11. +22
    -3
      models/membership.py
  12. +9
    -0
      models/partner.py
  13. +4
    -0
      report/report_invoice_document.xml
  14. +3
    -0
      security/ir.model.access.csv
  15. +68
    -29
      static/js/kalachakra.js
  16. +57
    -0
      views/accounting_file.xml
  17. +3
    -2
      views/booking_website_registration.xml
  18. +1
    -0
      views/membership.xml
  19. +2
    -0
      views/partner.xml
  20. +45
    -4
      views/website_event_registration.xml
  21. +3
    -0
      wizard/__init__.py
  22. +371
    -0
      wizard/accounting_file_wizard.py
  23. +33
    -0
      wizard/accounting_file_wizard.xml

+ 2
- 1
__init__.py View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from . import controllers
from . import models
from . import models
from . import wizard

+ 3
- 1
__manifest__.py View File

@ -70,7 +70,9 @@
'views/payment_transaction.xml',
'views/donation.xml',
'views/mediatheque.xml',
'views/account.xml'
'views/account.xml',
'views/accounting_file.xml',
'wizard/accounting_file_wizard.xml'
#'views/payment_views.xml'


+ 2
- 1
controllers/booking.py View File

@ -268,13 +268,14 @@ class booking(WebsiteEventController,AuthSignupHome):
else:
invoice=request.env['event.registration'].sudo().action_event_registration_generate_invoice(request.session['res_id'],False,False)
request.session['invoice_id']=invoice.id
#ajout de l'adhésion
if membership:
membership_product=request.env['product.product'].sudo().search([('membership_product','=',True)],limit=1)
if not membership_product: raise UserError(_('No membership product, please add one'))
vals={}
vals['invoice_id']=int(invoice.id)
vals['balance_invoice_id']=int(res.balance_invoice_id)
vals['partner_id']=int(res.partner_id)
vals['product_id']=int(membership_product.id)
vals['start_date']=datetime.now()


+ 12
- 12
controllers/kalachakra.py View File

@ -627,8 +627,9 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
if data['status']=='not member':data['status']='non adhérent'
if data['status']=='member':data['status']='adhérent'
if data['status']=='super member':data['status']='adhérent de soutien'
#data['form_action']='step2'
data['form_action']='contactform'
data['form_action']='step2'
#if not partner.phone or not partner.zip or not partner.city:
#data['form_action']='contactform'
if event.headphone_option :data['form_action']='step1b'
request.session['status']=partner.member_status
@ -751,16 +752,15 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
request.session['res_id']=res.id
#mise à jour des informations personnelles
partner.name=post.get('name')
partner.firstname=post.get('firstname')
partner.street=post.get('street')
partner.street2=post.get('street2')
partner.zip=post.get('zip')
partner.city=post.get('city')
partner.phone=post.get('phone')
partner.mobile=post.get('mobile')
if post.get('birthday_date')!='':
if post.get('name'):partner.name=post.get('name')
if post.get('firstname'):partner.firstname=post.get('firstname')
if post.get('street'):partner.street=post.get('street')
if post.get('street2'):partner.street2=post.get('street2')
if post.get('zip'):partner.zip=post.get('zip')
if post.get('city'):partner.city=post.get('city')
if post.get('phone'):partner.phone=post.get('phone')
if post.get('mobile'):partner.mobile=post.get('mobile')
if post.get('birthday_date'):
bd=post.get('birthday_date').split('/'
)
partner.birthday_date=bd[2]+'-'+bd[1]+'-'+bd[0]


+ 1
- 0
models/__init__.py View File

@ -23,4 +23,5 @@ from . import account_move
from . import res_users
from . import membership_import
from . import online_payment
from . import accounting_file

+ 1
- 0
models/account_move.py View File

@ -14,6 +14,7 @@ class AccountMove(models.Model):
transaction_date=fields.Datetime(compute='_compute_transaction_date')
transaction_amount=fields.Float(compute='_compute_transaction_amount')
systempay_ref=fields.Text(compute='_compute_systempay_ref')
date_compta=fields.Datetime('date import',default=False)
def _compute_description(self):


+ 13
- 0
models/accounting_file.py View File

@ -0,0 +1,13 @@
from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError,Warning
from datetime import date,datetime,timedelta
class accounting_file(models.Model):
_name = 'accounting.file'
_description = '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)

+ 1
- 0
models/booking_event_registration.py View File

@ -108,6 +108,7 @@ class EventRegistration(models.Model):
days_duration=fields.Integer('Duration in days')
price_individual_booking=fields.Monetary('price individual booking',currency_field='currency_id')
exported_state=fields.Char('accounting exported state')
def compute_individual_room(self):
for rec in self:


+ 1
- 0
models/donation.py View File

@ -47,6 +47,7 @@ class DonationDonation(models.Model):
affectation=fields.Char(compute='_compute_affectation')
source_import=fields.Char('source import')
date_import=fields.Date('date import',default=False)
date_compta=fields.Datetime('date import',default=False)
# @api.depends('transaction_id.state')
# def transaction_state(self):
# _logger.error("onchange_transaction_state")


+ 1
- 64
models/event.py View File

@ -211,6 +211,7 @@ class KalachakraEvent(models.Model):
child_event.online_link=rec.online_link
child_event.online_id=rec.online_id
child_event.online_password=rec.online_password
child_event.teacher_picto=rec.teacher_picto
child_event.event_logo=rec.event_logo
child_event.cover_properties=rec.cover_properties
@ -453,71 +454,7 @@ class KalachakraEvent(models.Model):
vals['currency_id']=option.currency_id
self.booking_option_ids = [(0, 0, vals)]
#suppression des 2 templates de mail
# self.event_mail_ids=False
# self.env['event.mail'].sudo().search([('event_id','=',self._origin.id)]).unlink()
# template_mail_reg=self.env['mail.template'].sudo().search([('name','=','Retraite : Inscription')])
# #création du mail d'enregistrement
# if template_mail_reg:
# vals={}
# vals['display_name']=template_mail_reg.name
# vals['event_id']=self._origin.id
# vals['template_id']=template_mail_reg.id
# vals['interval_nbr']=0
# vals['interval_unit']='now'
# vals['interval_type']='after_sub'
# mail=self.env['event.mail'].sudo().create(vals)
# self.event_mail_ids=[(4, mail.id)]
# template_mail_remind=self.env['mail.template'].sudo().search([('name','=','Retraite : Rappel')])
# #création du mail avant événement
# if template_mail_remind:
# vals={}
# vals['display_name']=template_mail_remind.name
# vals['event_id']=self._origin.id
# vals['template_id']=int(template_mail_remind.id)
# vals['interval_nbr']=5
# vals['interval_unit']='days'
# vals['interval_type']='before_event'
# mail=self.env['event.mail'].sudo().create(vals)
# self.event_mail_ids=[(4, mail.id)]
# #événement
# else:
# #suppression des 2 templates de mail
# self.event_mail_ids=False
# self.env['event.mail'].sudo().search([('event_id','=',self._origin.id)]).unlink()
# template_mail_reg=self.env['mail.template'].sudo().search([('name','=','Evénement : Inscription')])
# #création du mail d'enregistrement
# if template_mail_reg:
# vals={}
# vals['display_name']=template_mail_reg.name
# vals['event_id']=self._origin.id
# vals['template_id']=template_mail_reg.id
# vals['interval_nbr']=0
# vals['interval_unit']='now'
# vals['interval_type']='after_sub'
# mail=self.env['event.mail'].sudo().create(vals)
# self.event_mail_ids=[(4, mail.id)]
# template_mail_remind=self.env['mail.template'].sudo().search([('name','=','Evénement : Rappel')])
# #création du mail avant événement
# if template_mail_remind:
# vals={}
# vals['display_name']=template_mail_remind.name
# vals['event_id']=self._origin.id
# vals['template_id']=int(template_mail_remind.id)
# vals['interval_nbr']=5
# vals['interval_unit']='days'
# vals['interval_type']='before_event'
# mail=self.env['event.mail'].sudo().create(vals)
# self.event_mail_ids=[(4, mail.id)]


+ 22
- 3
models/membership.py View File

@ -28,9 +28,18 @@ class kalachakra_membership(models.Model):
product_id=fields.Many2one('product.product',required=True,string='membership product',default=_default_product_id,domain="[('membership_product','=',True)]")
start_date=fields.Date('start date',required=True,default=lambda self: fields.Date.today())
invoice_id=fields.Many2one('account.move','invoice')
balance_invoice_id=fields.Many2one('account.move','balance invoice')
transaction_id=fields.Many2one('payment.transaction','payment transaction')
payment_state=fields.Selection(string='payment_state',selection=[('paid', 'paid'), ('not paid', 'not paid')])
payment_mode_id = fields.Many2one(
"account.payment.mode",
string="Payment Mode",
domain="[('company_id', '=', company_id)]",
copy=False,
tracking=True
)
# @api.depends('state', 'invoice_id')
@ -79,13 +88,14 @@ class kalachakra_membership(models.Model):
tracking=True,
)
date_compta=fields.Datetime('date import',default=False)
@api.depends('invoice_id.payment_state','transaction_id.state')
@api.depends('invoice_id.payment_state','balance_invoice_id.payment_state','transaction_id.state')
def _compute_membership_state(self):
for m in self:
if m.invoice_id:
if m.invoice_id and not m.balance_invoice_id:
if m.invoice_id.payment_state=='paid':
m.payment_state='paid'
@ -94,6 +104,15 @@ class kalachakra_membership(models.Model):
m.payment_state='not paid'
m.state='draft'
if m.balance_invoice_id:
if m.balance_invoice_id.payment_state=='paid':
m.payment_state='paid'
m.state='done'
else:
m.payment_state='not paid'
m.state='draft'
if m.transaction_id:
if m.transaction_id.state=='done':


+ 9
- 0
models/partner.py View File

@ -64,6 +64,10 @@ class ResPartner(models.Model):
],'Origine', index=True)
date_adhesion=fields.Char(string='Date adhesion', readonly=True)
birthday_date=fields.Date(string="Birthday date")
birthday_yeardate=fields.Date(string="Birthday date")
name_for_list = fields.Char('name', compute='_compute_name_for_list',store=True)
def _compute_end_date_membership(self):
for rec in self:
@ -187,6 +191,11 @@ class ResPartner(models.Model):
if not mailing_list in mailing_contact.list_ids:
mailing_contact.sudo().write({'list_ids':[(4,int(mailing_list.id))]})
@api.depends('name')
def _compute_name_for_list(self):
for rec in self:
rec.name_for_list=rec.name
@api.depends('name','donor_id')
def name_get(self):
res = []


+ 4
- 0
report/report_invoice_document.xml View File

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
<xpath expr='//address[@t-field="o.partner_id"]' position="replace">
<span t-field="o.partner_id.name_for_list"/>
</xpath>
<xpath expr='//span[@t-field="o.name"]' position="replace">
<span t-if="o.name != '/'" t-field="o.name"/> <b>: <span t-field="o.payment_state"/></b>
</xpath>


+ 3
- 0
security/ir.model.access.csv View File

@ -27,3 +27,6 @@ access_event_teaching_session_portal,event_teaching_session_portal,model_event_t
access_event_teaching_day,event_media_dession,model_event_teaching_day,base.group_user,1,1,1,1
access_event_teaching_day_public,event_teaching_day_public,model_event_teaching_day,base.group_public,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_wizard,access to accounting file wizard,model_accounting_file_wizard,account.group_account_manager,1,1,1,1

+ 68
- 29
static/js/kalachakra.js View File

@ -1,4 +1,8 @@
odoo.define('kalachakra.main', function (require) {
var core = require('web.core');
var QWeb = core.qweb;
var _t = core._t;
if ($('#lang').val()=='en_GB')
{
@ -12,6 +16,7 @@ odoo.define('kalachakra.main', function (require) {
if ($('#lang').val()=='fr_FR')
{
var message_phone= 'merci de saisir votre numéro de mobile ou de téléphone'
var message_phone_invalid= 'le numéro de téléphone n\'est pas correct'
var message_name= 'merci de saisir votre nom'
var message_firstname= 'merci de saisir votre prénom'
var message_zip= 'merci de saisir votre code postal'
@ -20,52 +25,86 @@ odoo.define('kalachakra.main', function (require) {
$(document).ready(function() {
$('#datepickerbirthday_date').datetimepicker({
format: 'DD/MM/YYYY',
enableOnReadonly: true
});
});
function check_phone_mobile(phone)
{
var phoneno = /^\d{10}$/;
if((phone.match(phoneno)))
{
return true;
}
else
{
return false;
}
}
function check_zip(zip,country)
{
}
$( "#contact_form_continue_button" ).click(function() {
const mobile=$('#contact_mobile').val();
const phone=$('#contact_phone').val();
console.log(message_phone)
if (mobile.trim()=='' && phone.trim()=='')
{
$('#validation_message').text(message_phone)
$('#validation_message').show()
return;
}
else
if (check_phone_mobile(phone)==false && phone.trim()!='')
{
if ($('#contact_name').val().trim()=='')
{
$('#validation_message').text(message_name)
$('#validation_message').show()
}
else if ($('#contact_firstname').val().trim()=='')
{
$('#validation_message').text(message_firstname)
$('#validation_message').show()
}
$('#validation_message').text(message_phone_invalid)
$('#validation_message').show()
return;
}
if (check_phone_mobile(mobile)==false && mobile.trim()!='')
{
$('#validation_message').text(message_phone_invalid)
$('#validation_message').show()
return;
}
if ($('#contact_name').val().trim()=='')
{
$('#validation_message').text(message_name)
$('#validation_message').show()
return;
else if ($('#contact_city').val().trim()=='')
{
$('#validation_message').text(message_city)
$('#validation_message').show()
}
else
{
$('#form1').submit()
}
}
if ($('#contact_firstname').val().trim()=='')
{
$('#validation_message').text(message_firstname)
$('#validation_message').show()
return;
}
if ($('#contact_city').val().trim()=='')
{
$('#validation_message').text(message_city)
$('#validation_message').show()
return;
}
$('#form1').submit()
});


+ 57
- 0
views/accounting_file.xml View File

@ -0,0 +1,57 @@
<odoo>
<data>
<record model="ir.ui.view" id="kalachakra.accounting_file_list">
<field name="name">kalachakra_member list</field>
<field name="model">accounting.file</field>
<field name="arch" type="xml">
<tree default_order='create_date desc'>
<field name="create_date"/>
<field name="exported_date"/>
</tree>
</field>
</record>
<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="arch" type="xml">
<form>
<!-- <header> <button type="object" name="action_create_accounting_file" string="Generate csv export"/>
</header> -->
<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="exported_date"/>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="accounting_file_action">
<field name="name">Accounting files</field>
<field name="res_model">accounting.file</field>
<field name="view_mode">tree,form,pivot</field>
</record>
<menuitem id="accounting_file_menu" action="accounting_file_action"
parent="account.menu_finance_entries_accounting_miscellaneous" sequence="10"/>
</data>
</odoo>

+ 3
- 2
views/booking_website_registration.xml View File

@ -101,12 +101,13 @@
class="form-control datetimepicker-input"
data-target="#datetimepickerstart_day"
name="start_day" id="start_day" value="" />
</div>
<div class="input-group-append"
<div class="input-group-append"
data-target="#datetimepickerstart_day"
data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
</div>


+ 1
- 0
views/membership.xml View File

@ -39,6 +39,7 @@
</group>
<group>
<field name="invoice_id"/>
<field name="balance_invoice_id"/>
<field name="transaction_id"/>
<field name="payment_state"/>


+ 2
- 0
views/partner.xml View File

@ -27,6 +27,8 @@
<field name="member_status" widget='label_selection'/>
<field name="date_membership"/>
<field name="super_member"/>
<field name="birthday_date"/>
</xpath>
<xpath expr="//field[@name='title']" position="replace">


+ 45
- 4
views/website_event_registration.xml View File

@ -4,7 +4,7 @@
<xpath expr="." position="inside">
<script type="text/javascript" src="/kalachakra/static/js/kalachakra.js"></script>
<script type="text/javascript" src="/kalachakra/static/js/Datejs/build/date-fr-FR.js"></script>
</xpath>
</template>
@ -311,10 +311,10 @@
<t t-call="website.layout">
<div class="container-fluid">
<form id="form1" action="questionnaire" method="post" class="form js_website_submit_form">
<form id="form1" t-att-action="'step2?event_id='+str(event.id)" method="post" class="form js_website_submit_form">
<input type="hidden" id="lang" t-att-value="lang"/>
<section class="s_website_form pt16 pb16 o_colored_level">
<h6>To contact you if needed, please filling your personnals informations :</h6>
<h6>Please fill in or update your personnals informations :</h6>
<div class="form-group s_website_form_field s_website_form_custom s_website_form_required" data-type="char" data-name="Field">
<div class="row s_col_no_resize s_col_no_bgcolor">
@ -334,12 +334,35 @@
<span class="s_website_form_mark"> *</span>
</label>
<div class="col-12 col-sm-12 col-md-6 col-lg-4 col-xl-3">
<input type="text" class="form-control s_website_form_input" name="contact_firstname" t-att-value="partner.firstname" required="1" id="contact_firstname" style="cursor: auto;"/>
<input type="text" class="form-control s_website_form_input" name="firstname" t-att-value="partner.firstname" required="1" id="contact_firstname" style="cursor: auto;"/>
</div>
</div>
</div>
<div class="form-group s_website_form_field s_website_form_custom" data-type="date" data-name="Field">
<div class="row s_col_no_resize s_col_no_bgcolor">
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 200px" for="ofy6dixdwt">
<span class="s_website_form_label_content">Birthday date</span>
</label>
<div class="col-12 col-sm-12 col-md-6 col-lg-4 col-xl-3">
<div class="s_website_form_date input-group datetime" id="datepickerbirthday_date" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input"
data-target="#datepickerbirthday_date" name="birthday_date"
placeholder="" id="birthday_date"/>
<div class="input-group-append"
data-target="#datepickerbirthday_date" data-toggle="datetimepicker">
<div class="input-group-text">
<i class="fa fa-calendar"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="form-group s_website_form_field s_website_form_custom" data-type="char" data-name="Field">
<div class="row s_col_no_resize s_col_no_bgcolor">
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 200px" for="9ois9pkv0wv">
@ -389,6 +412,24 @@
</div>
</div>
</div>
<input type="hidden" name="country_france_id" t-att-value="country_france_id"/>
<div class="form-group s_website_form_field s_website_form_custom" id="div_country">
<div class="row s_col_no_resize s_col_no_bgcolor">
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 200px" for="country_id">Country<span class="s_website_form_mark"> *</span>
</label>
<div class="col-12 col-sm-12 col-md-4 col-lg-2 col-xl-2">
<select id="country_id" name="country_id" class="o_wpayment_fee_impact form-control ">
<t t-foreach="countries" t-as="country">
<option t-att-selected="country.id==country_id" t-att-value="country.id" t-esc="country.name"></option>
</t>
</select>
</div>
</div>
</div>
<div class="form-group s_website_form_field s_website_form_custom " data-type="char" data-name="Field">
<div class="row s_col_no_resize s_col_no_bgcolor">
<label class="col-form-label col-sm-auto s_website_form_label" style="width: 200px" for="9ois9pkv0wv">


+ 3
- 0
wizard/__init__.py View File

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

+ 371
- 0
wizard/accounting_file_wizard.py View File

@ -0,0 +1,371 @@
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
class AccountingFileWizard(models.TransientModel):
_name = 'accounting.file.wizard'
_description = 'accounting file wizard'
#accounting_date=fields.Date(string='Accounting date',required=True)
def action_create_accounting_file(self):
#debug
donation=self.env['donation.donation'].search([])
for d in donation:
d.date_compta=False
tmstp=secrets.token_hex(16)
filename='/tmp/accounting_file_'+tmstp+'.txt'
f = open(filename, "a")
date_compta=fields.datetime.now()
#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
no_mvt=1
code_journal='IN'
fic_line="N° mouvement;Code du journal;Date;N° de compte;Libellé;Débit;Crédit;N° de pièce"+"\n"
f.write(fic_line)
#é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')])
for d in donation:
#on ne prend pas en compte les dons liés à une retraite
#car traité avec les retraites
if d.invoice_id: continue
d.date_compta=date_compta
account_debit_number=self._file_format(str(d.payment_mode_id.fixed_journal_id.default_account_id.code),6)
firstname=d.partner_id.firstname
name=d.partner_id.name
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
#lib1=lib1[11]
date_line=self._date_format(str(d.donation_date))
#recherche de la transaction
lib_piece=self._file_format(d.number,20)
pt=self.env['payment.transaction'].search([('donation_ids','in',d.id)])
if pt: lib_piece=pt.reference
for line in d.line_ids:
affectation=line.product_id.name
amount=str(line.amount)
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)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_credit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
#debit line
debit=str(amount)
credit=''
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_debit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
#écritures pour les ADHESIONS réglées non déjà exportés
membership=self.env['kalachakra.membership'].search([('date_compta','=',False),('state','=','done')])
for m in membership:
m.date_compta=date_compta
#on ne prend pas en compte les adhésions liés à une retraite
#car traité avec les retraites
if m.invoice_id: continue
#si l'adhésion est liée à une facture, alors on récupère la facture pour trouver le mode de paiement
if m.invoice_id:
account_debit_number=self._file_format(str(m.invoice_id.payment_id.fixed_journal_id.default_account_id.code),6)
#si l'adhésion est liée à une transaction,le mode de paiement est CB
elif m.transaction_id:
CB_pm=self.env['account.payment.mode'].search([('name','=','CB')],limit=1)
if CB_pm:
account_debit_number=self._file_format(str(CB_pm.fixed_journal_id.default_account_id.code),6)
else:
raise UserError(_('please configure CB payement mode'))
#sinon on prend le mode de paiement au niveau de la fiche d'adhésion
else:
if m.payment_mode_id:
account_debit_number=self._file_format(str(m.payment_mode_id.fixed_journal_id.default_account_id.code),6)
firstname=m.partner_id.firstname
name=m.partner_id.name
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
date_line=self._date_format(str(m.start_date))
amount=str(m.amount)
account_credit_number=self._file_format(m.product_id.property_account_income_id.code,6)
affectation=m.product_id.name
#lib pièce
if m.transaction_id:
lib_piece=self._file_format(m.transaction_id.reference,20)
elif m.invoice_id:
lib_piece=self._file_format(m.invoice_id.name,20)
else:
lib_piece=self._file_format(m.id,20)
#credit line
lib2=self._file_format(affectation,13)
lib=lib1+' '+lib2
debit=''
credit=str(amount)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_credit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
#debit line
debit=str(amount)
credit=''
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_debit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
#écritures pour les inscriptions évts hors RETRAITES avec facture payée non déjà exportés
move=self.env['account.move'].search([('date_compta','=',False),('payment_state','=','paid')])
for m in move:
reg=self.env['event.registration'].search([('invoice_id','=',int(move.id))])
if reg:
if not reg.event_id.booking_event and not reg.event_id.individual_booking_event:
m.date_compta=date_compta
account_debit_number=self._file_format(str(m.payment_id.fixed_journal_id.default_account_id.code),6)
firstname=m.partner_id.firstname
name=m.partner_id.name
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
#date du paiement
date_line=self._date_format(str(m.write_date))
amount=str(m.amount_total)
account_credit_number=self._file_format(reg.event_id.participation_product_id.property_account_income_id.code,6)
affectation=reg.event_id.participation_product_id.name
#si facture liée à une transaction:
trans=self.env['payment.transaction'].search([('invoice_ids','in',m.id)])
if trans:
lib_piece=self._file_format(trans.reference,20)
else:
lib_piece=self._file_format(m.name,20)
#credit line
lib2=self._file_format(affectation,13)
lib=lib1+' '+lib2
debit=''
credit=str(amount)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_credit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
#debit line
debit=str(amount)
credit=''
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_debit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
#écritures pour les inscription aux RETRAITES avec facture acomptes payés + factures soldes payés non déjà exporté
reg=self.env['event.registration'].search(['|',('date_compta','=',False),('date_compta_down_payment','!=',False)])
if reg:
reg.date_compta=date_compta
account_credit_number=self._file_format(reg.event_id.participation_product_id.property_account_income_id.code,6)
account_debit_number=self._file_format(str(m.payment_id.fixed_journal_id.default_account_id.code),6)
firstname=reg.firstname
name=reg.name
lib1=firstname[0]+' '+name
lib1=self._file_format(lib1,12)
lib2=self._file_format(reg.event_id.participation_product_id.name,13)
lib=lib1+' '+lib2
#si pas de facture d'acompte et facture payée:
if not down_payment_invoice_id and reg.payment_status=='paid' and not reg.date_compta :
down_payment=False
balance_payment=False
amount=reg.invoice_id.amount_total
#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
#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
date_line=self._date_format(str(reg.invoice_id.write_date))
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.invoice_id)])
#si facture d'acompte payée et solde payée et pas encore exportée :
if reg.payment_status=='paid' and not reg.date_compta:
reg.date_compta=date_compta
down_payment=True
balance_payment=True
membership_amount=0
donation_amount=0
amount=reg.down_payment_invoice_id.amount_total+reg.balance_invoice_id.amount_total
date_line=self._date_format(str(reg.balance_invoice_id.write_date))
#recherche de l'adhésion
membership_credit_line=False
membership=self.env['kalachakra.membership'].search([('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([('invoice_id','=',int(reg.balance_invoice_id))])
if donations:
donation_credit_line=True
for d in donations:
donation_amount=donation_amount+d.amount_total
trans=self.env['payment.transaction'].search([('invoice_ids','in',reg.invoice_id)])
#si facture d'acompte payée pas encore exporté et solde non payée :
if reg.payment_status=='down payment paid' and not reg.date_compta_down_payment:
reg.date_compta_down_payment=date_compta
down_payment=True
balance_payment=False
donation_credit_line=False
membership_credit_line=False
amount=reg.down_payment_invoice_id.amount_total
date_line=self._date_format(str(reg.down_payment_invoice_id.write_date))
#si facture d'acompte payée et exporté et solde payée pas exporté :
if reg.payment_status=='paid' and reg.date_compta_down_payment:
reg.date_compta=date_compta
down_payment=False
balance_payment=True
date_line=self._date_format(str(reg.balance_invoice_id.write_date))
#recherche de l'adhésion
membership_credit_line=False
membership=self.env['kalachakra.membership'].search([('balance_invoice_id','=',int(reg.balance_invoice_id))])
if membership:membership_credit_line=True
#recherche de dons
donation_credit_line=False
donations=donation_booking=self.env['donation.donation'].search([('invoice_id','=',int(reg.balance_invoice_id))])
if donations:
donation_credit_line=True
for d in donations:
amount_donation=amount_donation+donations.amount_total
#écritures pour les inscription aux RETRAITES avec facture complémentaire
if trans:
lib_piece=self._file_format(trans.reference,20)
else:
lib_piece=self._file_format(lib2,20)
#debit line
debit=str(amount)
credit=''
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_debit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
#credit(s) line(s)
#participation credit line
amount=amount-membership_amount-donation_amount
debit=''
credit=str(amount)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_credit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
if membership_credit_line:
debit=''
credit=str(membership_amount)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_credit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
if donation_credit_line:
for d in donations :
debit=''
credit=str(d.amount_total)
fic_line=str(no_mvt)+';'+'IN'+';'+date_line+';'+account_credit_number+';'+lib+';'+debit+';'+credit+';'+lib_piece+'\n'
f.write(fic_line)
no_mvt=no_mvt+1
#rajouter en fin de fichier un total DEBIT et un total CREDIT
f.close
#création de l'export en base
vals={}
f = open(filename, "r")
data = str.encode(f.read(), 'utf-8')
vals['accounting_file']=base64.encodebytes(data)
vals['document_fname']='export_comptable.csv'
vals['exported_date']=fields.Date.context_today(self)
res=self.env['accounting.file'].create(vals)
f.close
os.unlink(filename)
#affichage de l'export
return {
'name': 'Account file form',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'accounting.file',
'res_id': int(res.id),
'type': 'ir.actions.act_window',
'target': 'current'
}
return True
def _file_format(self,data,nbcars):
if data:
if len(data)>nbcars:
return data[nbcars]
else:
return data
else:
return ''
def _date_format(self,data):
r=data.split('-')
return r[2]+'/'+r[1]+'/'+r[0]

+ 33
- 0
wizard/accounting_file_wizard.xml View File

@ -0,0 +1,33 @@
<odoo>
<record id="accounting_file_wizard_view" model="ir.ui.view">
<field name="name">accounting_file_wizard view</field>
<field name="model">accounting.file.wizard</field>
<field name="arch" type="xml">
<form string="Accounting file wizard">
<group>
<button name="action_create_accounting_file" string="generate accounting file" type="object"/>
</group>
<footer>
<button string="Cancel" class="btn btn-secondary" special="cancel" />
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="generate_accounting_file_action">
<field name="name">Generate accounting file</field>
<field name="res_model">accounting.file.wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem id="accounting_file_generate_menu" action="generate_accounting_file_action"
parent="account.menu_finance_entries_accounting_miscellaneous" sequence="11"/>
</odoo>

Loading…
Cancel
Save