cleanup storage of subscriptions
This commit is contained in:
parent
8c75c1836f
commit
b9602c1593
|
@ -1,3 +1,4 @@
|
|||
from dataclasses import dataclass
|
||||
from schwifty import IBAN
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
@ -5,17 +6,16 @@ import typing
|
|||
import logging
|
||||
from bij1.erp import pool
|
||||
from bij1.erp.config import config
|
||||
from pydantic import BaseModel, EmailStr
|
||||
from pydantic_extra_types.phone_numbers import PhoneNumber
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Member(BaseModel):
|
||||
@dataclass
|
||||
class Member:
|
||||
name: str
|
||||
email: EmailStr
|
||||
phone: typing.Optional[PhoneNumber] = None
|
||||
email: typing.Optional[str] = None
|
||||
phone: typing.Optional[str] = None
|
||||
address: typing.Optional[str] = None
|
||||
postcode: typing.Optional[str] = None
|
||||
city: typing.Optional[str] = None
|
||||
|
@ -176,6 +176,7 @@ class Member(BaseModel):
|
|||
def save_subscription(self):
|
||||
if not self.period:
|
||||
return
|
||||
|
||||
Subscription = pool.get("sale.subscription")
|
||||
SubscriptionLine = pool.get("sale.subscription.line")
|
||||
SubscriptionService = pool.get("sale.subscription.service")
|
||||
|
@ -197,7 +198,18 @@ class Member(BaseModel):
|
|||
else:
|
||||
subscription = subscription[0]
|
||||
|
||||
if self.until:
|
||||
subscription.end_date = self.until
|
||||
|
||||
subscription.description = config.subscription_description
|
||||
|
||||
if self.until and self.until < date(2024, 1, 1):
|
||||
if lines := SubscriptionLine.search(
|
||||
[("subscription", "=", subscription), ("service", "=", service)]
|
||||
):
|
||||
SubscriptionLine.delete(lines)
|
||||
return
|
||||
|
||||
subscription.save()
|
||||
|
||||
if not (
|
||||
|
@ -211,8 +223,14 @@ class Member(BaseModel):
|
|||
line.quantity = 1
|
||||
line.unit_price = self.amount
|
||||
line.start_date = max([self.since, date(2024, 1, 1)])
|
||||
line.end_date = self.until
|
||||
line.unit = service.product.default_uom
|
||||
line.save()
|
||||
else:
|
||||
line = line[0]
|
||||
|
||||
line.save()
|
||||
Subscription.quote([subscription])
|
||||
Subscription.run([subscription])
|
||||
|
||||
def update(self):
|
||||
# XXX: to be improved
|
||||
|
|
Loading…
Reference in New Issue