Compare commits

...

3 Commits

  1. 6
      easy_my_coop/models/account_invoice.py
  2. 15
      easy_my_coop/models/coop.py
  3. 21
      easy_my_coop_website/controllers/main.py

6
easy_my_coop/models/account_invoice.py

@ -2,11 +2,11 @@
# Houssine Bakkali <houssine@coopiteasy.be> # Houssine Bakkali <houssine@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
from datetime import datetime from datetime import datetime
from odoo import api, fields, models from odoo import api, fields, models
_logger = logging.getLogger(__name__)
class AccountInvoice(models.Model): class AccountInvoice(models.Model):
_inherit = "account.invoice" _inherit = "account.invoice"
@ -114,7 +114,7 @@ class AccountInvoice(models.Model):
def send_certificate_email(self, certificate_email_template, sub_reg_line): def send_certificate_email(self, certificate_email_template, sub_reg_line):
# we send the email with the certificate in attachment # we send the email with the certificate in attachment
certificate_email_template.sudo().send_mail(self.partner_id.id, False)
certificate_email_template.sudo().send_mail(self.id, False)
def set_cooperator_effective(self, effective_date): def set_cooperator_effective(self, effective_date):
sub_register_obj = self.env["subscription.register"] sub_register_obj = self.env["subscription.register"]

15
easy_my_coop/models/coop.py

@ -16,13 +16,11 @@ _REQUIRED = [
"firstname", "firstname",
"lastname", "lastname",
"birthdate", "birthdate",
"street_name",
"house_number",
"address",
"share_product_id", "share_product_id",
"ordered_parts", "ordered_parts",
"zip_code", "zip_code",
"city", "city",
"iban",
"gender", "gender",
] ]
@ -701,10 +699,17 @@ class SubscriptionRequest(models.Model):
if self.is_company and not partner.has_representative(): if self.is_company and not partner.has_representative():
contact = False contact = False
if self.email: if self.email:
domain = [("email", "=", self.email)]
domain = [("email", "=", self.email),
('company_type', '=', 'person')]
contact = partner_obj.search(domain) contact = partner_obj.search(domain)
if contact:
if len(contact) < 2:
contact.type = "representative" contact.type = "representative"
else:
raise UserError(
_(
"You have duplicate contact with email %s" % self.email
)
)
if not contact: if not contact:
contact_vals = self.get_representative_vals() contact_vals = self.get_representative_vals()
partner_obj.create(contact_vals) partner_obj.create(contact_vals)

21
easy_my_coop_website/controllers/main.py

@ -10,7 +10,7 @@ from odoo.tools.translate import _
_TECHNICAL = ["view_from", "view_callback"] _TECHNICAL = ["view_from", "view_callback"]
# transient fields used to compute the address field # transient fields used to compute the address field
_EXTRA_FIELDS = ["street_name", "house_number"]
_EXTRA_FIELDS = []
# Allow in description # Allow in description
_BLACKLIST = [ _BLACKLIST = [
@ -31,8 +31,7 @@ _COOP_FORM_FIELD = [
"birthdate", "birthdate",
"iban", "iban",
"share_product_id", "share_product_id",
"street_name",
"house_number",
"address",
"city", "city",
"zip_code", "zip_code",
"country_id", "country_id",
@ -55,8 +54,7 @@ _COMPANY_FORM_FIELD = [
"birthdate", "birthdate",
"iban", "iban",
"share_product_id", "share_product_id",
"street_name",
"house_number",
"address",
"city", "city",
"zip_code", "zip_code",
"country_id", "country_id",
@ -301,7 +299,8 @@ class WebsiteSubscription(http.Controller):
if error: if error:
values = self.fill_values(values, is_company, logged) values = self.fill_values(values, is_company, logged)
values["error_msg"] = _( values["error_msg"] = _(
"Some mandatory fields have not " "been filled"
"Some mandatory fields have not "
"been filled (%s)" % error
) )
values = dict(values, error=error, kwargs=kwargs.items()) values = dict(values, error=error, kwargs=kwargs.items())
return request.render(redirect, values) return request.render(redirect, values)
@ -344,7 +343,8 @@ class WebsiteSubscription(http.Controller):
return request.render(redirect, values) return request.render(redirect, values)
iban = kwargs.get("iban") iban = kwargs.get("iban")
if iban.strip():
if iban:
iban.strip()
valid = sub_req_obj.check_iban(iban) valid = sub_req_obj.check_iban(iban)
if not valid: if not valid:
@ -469,13 +469,6 @@ class WebsiteSubscription(http.Controller):
values["share_product_id"] = self.get_selected_share(kwargs).id values["share_product_id"] = self.get_selected_share(kwargs).id
values["address"] = "{street}, {number}".format(
street=kwargs.get("street_name", ""),
number=kwargs.get("house_number", ""),
)
del values["street_name"]
del values["house_number"]
if is_company: if is_company:
if kwargs.get("company_register_number", is_company): if kwargs.get("company_register_number", is_company):
values["company_register_number"] = re.sub( values["company_register_number"] = re.sub(

Loading…
Cancel
Save