from odoo import models, fields, api
from odoo.exceptions import UserError, ValidationError, Warning
from psycopg2 import sql, DatabaseError
import logging
from werkzeug import utils
import re
_logger = logging.getLogger(__name__)

class AccountMove(models.Model):
    _inherit = 'account.move'

    def write(self,vals):
            res=super(AccountMove, self).write(vals)
            
            m=self.env['kalachakra.membership'].sudo().search([('invoice_id','=',int(self.id))])
            
            if m:
                if self.payment_state == 'not_paid':
                    m.payment_state='not paid'
                    m.state='draft'
                else:
                    m.payment_state='paid'
                    m.state='done'
                _logger.error("errK2"+str(m.payment_state))
            
            return res
            
                
