|
|
@ -1,6 +1,8 @@ |
|
|
|
from odoo import models, fields, api |
|
|
|
from odoo.exceptions import UserError, ValidationError, Warning |
|
|
|
from psycopg2 import sql, DatabaseError |
|
|
|
from datetime import date,datetime,timedelta |
|
|
|
from dateutil.relativedelta import relativedelta |
|
|
|
import logging |
|
|
|
from werkzeug import utils |
|
|
|
import re |
|
|
@ -20,6 +22,44 @@ class AccountMove(models.Model): |
|
|
|
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') |
|
|
|
|
|
|
|
def write(self, data): |
|
|
|
|
|
|
|
|
|
|
|
res = super(AccountMove, self).write(data) |
|
|
|
membership=False |
|
|
|
#Si option d'adhesion on prepare la creation de l'adhesion |
|
|
|
membership_product=self.env['product.product'].sudo().search([('membership_product','=',True)],limit=1) |
|
|
|
for line in self.invoice_line_ids: |
|
|
|
if membership_product.id==int(line.product_id.id): |
|
|
|
membership=True |
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.payment_state=='paid' and membership: |
|
|
|
#recherche de l'ahésion associée à la facture |
|
|
|
m=self.env['kalachakra.membership'].search([('invoice_id','=',int(self.id))]) |
|
|
|
if m: |
|
|
|
m.start_date=datetime.now() |
|
|
|
m.end_date=datetime.now()+relativedelta(years=1) |
|
|
|
#m.email_confirmation() |
|
|
|
|
|
|
|
#mise à jour des dates adhésions à partir de la date de paiement |
|
|
|
else: |
|
|
|
#création de l'adhésion |
|
|
|
vals={} |
|
|
|
vals['invoice_id']=int(self.id) |
|
|
|
vals['partner_id']=int(self.partner_id) |
|
|
|
vals['product_id']=int(membership_product.id) |
|
|
|
vals['start_date']=datetime.now() |
|
|
|
vals['end_date']=datetime.now()+relativedelta(years=1) |
|
|
|
vals['amount']=line.price_unit |
|
|
|
vals['state']='done' |
|
|
|
membership=self.env['kalachakra.membership'].sudo().create(vals) |
|
|
|
|
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
def _compute_payment_ids(self): |
|
|
|
|
|
|
|
payments=self.env['account.payment'].sudo().search([]) |
|
|
|