Compare commits

...

5 Commits

  1. 2
      easy_my_coop/__manifest__.py
  2. 6
      easy_my_coop/models/account_invoice.py
  3. 49
      easy_my_coop/models/coop.py
  4. 21
      easy_my_coop_website/controllers/main.py

2
easy_my_coop/__manifest__.py

@ -18,7 +18,7 @@
"partner_age",
"partner_firstname",
"partner_contact_birthdate",
"partner_contact_address",
#"partner_contact_address",
"email_template_config",
],
"author": "Coop IT Easy SCRLfs",

6
easy_my_coop/models/account_invoice.py

@ -2,11 +2,11 @@
# Houssine Bakkali <houssine@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
from datetime import datetime
from odoo import api, fields, models
_logger = logging.getLogger(__name__)
class AccountInvoice(models.Model):
_inherit = "account.invoice"
@ -114,7 +114,7 @@ class AccountInvoice(models.Model):
def send_certificate_email(self, certificate_email_template, sub_reg_line):
# 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):
sub_register_obj = self.env["subscription.register"]

49
easy_my_coop/models/coop.py

@ -16,13 +16,11 @@ _REQUIRED = [
"firstname",
"lastname",
"birthdate",
"street_name",
"house_number",
"address",
"share_product_id",
"ordered_parts",
"zip_code",
"city",
"iban",
"gender",
]
@ -70,9 +68,7 @@ class SubscriptionRequest(models.Model):
if not vals.get("partner_id"):
cooperator = False
if vals.get("email"):
cooperator = partner_obj.get_cooperator_from_email(
vals.get("email")
)
cooperator = partner_obj.get_cooperator_from_email(vals.get("email"))
if cooperator:
# TODO remove the following line once it has
# been found a way to avoid double encoding
@ -107,9 +103,7 @@ class SubscriptionRequest(models.Model):
vals["already_cooperator"] = True
subscr_request = super(SubscriptionRequest, self).create(vals)
confirmation_mail_template = subscr_request.get_mail_template_notif(
True
)
confirmation_mail_template = subscr_request.get_mail_template_notif(True)
confirmation_mail_template.send_mail(subscr_request.id)
return subscr_request
@ -133,20 +127,15 @@ class SubscriptionRequest(models.Model):
@api.depends("iban", "skip_control_ng")
def _compute_validated_lines(self):
for sub_request in self:
validated = sub_request.skip_control_ng or self.check_iban(
sub_request.iban
)
validated = sub_request.skip_control_ng or self.check_iban(sub_request.iban)
sub_request.validated = validated
@api.multi
@api.depends(
"share_product_id", "share_product_id.list_price", "ordered_parts"
)
@api.depends("share_product_id", "share_product_id.list_price", "ordered_parts")
def _compute_subscription_amount(self):
for sub_request in self:
sub_request.subscription_amount = (
sub_request.share_product_id.list_price
* sub_request.ordered_parts
sub_request.share_product_id.list_price * sub_request.ordered_parts
)
already_cooperator = fields.Boolean(
@ -428,9 +417,7 @@ class SubscriptionRequest(models.Model):
readonly=True,
states={"draft": [("readonly", False)]},
)
data_policy_approved = fields.Boolean(
string="Data Policy Approved", default=False
)
data_policy_approved = fields.Boolean(string="Data Policy Approved", default=False)
internal_rules_approved = fields.Boolean(
string="Approved Internal Rules", default=False
)
@ -531,9 +518,7 @@ class SubscriptionRequest(models.Model):
if accounts:
account = accounts[0]
else:
raise UserError(
_("You must set a cooperator account on you company.")
)
raise UserError(_("You must set a cooperator account on you company."))
return account
def get_invoice_vals(self, partner):
@ -701,10 +686,14 @@ class SubscriptionRequest(models.Model):
if self.is_company and not partner.has_representative():
contact = False
if self.email:
domain = [("email", "=", self.email)]
domain = [("email", "=", self.email), ("company_type", "=", "person")]
contact = partner_obj.search(domain)
if contact:
if len(contact) < 2:
contact.type = "representative"
else:
raise UserError(
_("You have duplicate contact with email %s" % self.email)
)
if not contact:
contact_vals = self.get_representative_vals()
partner_obj.create(contact_vals)
@ -717,7 +706,7 @@ class SubscriptionRequest(models.Model):
" proceed to a merge before to continue"
)
)
if contact.parent_id and contact.parent_id.id != partner.id:
if contact.parent_id and contact.parent_id.id != partner.parent_id.id:
raise UserError(
_(
"This contact person is already defined"
@ -726,9 +715,7 @@ class SubscriptionRequest(models.Model):
)
)
else:
contact.write(
{"parent_id": partner.id, "representative": True}
)
contact.write({"representative": True})
invoice = self.create_invoice(partner)
self.write({"state": "done"})
@ -838,9 +825,7 @@ class SubscriptionRegister(models.Model):
partner_id_to = fields.Many2one(
"res.partner", string="Transfered to", readonly=True
)
date = fields.Date(
string="Subscription Date", required=True, readonly=True
)
date = fields.Date(string="Subscription Date", required=True, readonly=True)
quantity = fields.Integer(string="Number of share", readonly=True)
share_unit_price = fields.Monetary(
string="Share price",

21
easy_my_coop_website/controllers/main.py

@ -10,7 +10,7 @@ from odoo.tools.translate import _
_TECHNICAL = ["view_from", "view_callback"]
# transient fields used to compute the address field
_EXTRA_FIELDS = ["street_name", "house_number"]
_EXTRA_FIELDS = []
# Allow in description
_BLACKLIST = [
@ -31,8 +31,7 @@ _COOP_FORM_FIELD = [
"birthdate",
"iban",
"share_product_id",
"street_name",
"house_number",
"address",
"city",
"zip_code",
"country_id",
@ -55,8 +54,7 @@ _COMPANY_FORM_FIELD = [
"birthdate",
"iban",
"share_product_id",
"street_name",
"house_number",
"address",
"city",
"zip_code",
"country_id",
@ -301,7 +299,8 @@ class WebsiteSubscription(http.Controller):
if error:
values = self.fill_values(values, is_company, logged)
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())
return request.render(redirect, values)
@ -344,7 +343,8 @@ class WebsiteSubscription(http.Controller):
return request.render(redirect, values)
iban = kwargs.get("iban")
if iban.strip():
if iban:
iban.strip()
valid = sub_req_obj.check_iban(iban)
if not valid:
@ -469,13 +469,6 @@ class WebsiteSubscription(http.Controller):
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 kwargs.get("company_register_number", is_company):
values["company_register_number"] = re.sub(

Loading…
Cancel
Save