Skip to content

Commit

Permalink
[IMP] subscription_oca: more invoicing modes
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyasProgrammer committed Jan 21, 2024
1 parent 032e0dc commit a41e59c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
33 changes: 25 additions & 8 deletions subscription_oca/models/sale_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,35 +321,52 @@ def generate_invoice(self):
if self.template_id.invoicing_mode != "draft":
invoice.action_post()
if self.template_id.invoicing_mode == "invoice_send":
mail_template = self.template_id.invoice_mail_template_id
invoice.with_context(force_send=True).message_post_with_template(
mail_template.id,
composition_mode="comment",
email_layout_xmlid="mail.mail_notification_paynow",
)
self.send_invoice(invoice)
invoice_number = invoice.name
message_body = (
"<b>%s</b> <a href=# data-oe-model=account.move data-oe-id=%d>%s</a>"
% (msg_static, invoice.id, invoice_number)
)

if self.template_id.invoicing_mode == "sale_and_invoice":
elif self.template_id.invoicing_mode in ["sale_draft"]:
self.create_sale_order()

Check warning on line 332 in subscription_oca/models/sale_subscription.py

View check run for this annotation

Codecov / codecov/patch

subscription_oca/models/sale_subscription.py#L332

Added line #L332 was not covered by tests

elif self.template_id.invoicing_mode in ["sale_confirmed"]:
order_id = self.create_sale_order()
order_id.action_confirm()

Check warning on line 336 in subscription_oca/models/sale_subscription.py

View check run for this annotation

Codecov / codecov/patch

subscription_oca/models/sale_subscription.py#L335-L336

Added lines #L335 - L336 were not covered by tests

elif self.template_id.invoicing_mode in [
"sale_and_invoice",
"sale_and_invoice_draft",
"sale_and_invoice_send",
]:
order_id = self.create_sale_order()
order_id.action_done()
new_invoice = order_id._create_invoices()
new_invoice.action_post()
if self.template_id.invoicing_mode == "sale_and_invoice":
new_invoice.action_post()
new_invoice.invoice_origin = order_id.name + ", " + self.name
invoice_number = new_invoice.name
message_body = (
"<b>%s</b> <a href=# data-oe-model=account.move data-oe-id=%d>%s</a>"
% (msg_static, new_invoice.id, invoice_number)
)
if self.template_id.invoicing_mode == "sale_and_invoice_send":
self.send_invoice(new_invoice)

Check warning on line 355 in subscription_oca/models/sale_subscription.py

View check run for this annotation

Codecov / codecov/patch

subscription_oca/models/sale_subscription.py#L355

Added line #L355 was not covered by tests
if not invoice_number:
invoice_number = _("To validate")
message_body = "<b>%s</b> %s" % (msg_static, invoice_number)
self.calculate_recurring_next_date(self.recurring_next_date)
self.message_post(body=message_body)

def send_invoice(self, invoice):
mail_template = self.template_id.invoice_mail_template_id
invoice.with_context(force_send=True).message_post_with_template(
mail_template.id,
composition_mode="comment",
email_layout_xmlid="mail.mail_notification_paynow",
)

def manual_invoice(self):
invoice_id = self.create_invoice()
self.calculate_recurring_next_date(self.recurring_next_date)
Expand Down
4 changes: 4 additions & 0 deletions subscription_oca/models/sale_subscription_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class SaleSubscriptionTemplate(models.Model):
("invoice", "Invoice"),
("invoice_send", "Invoice & send"),
("sale_and_invoice", "Sale order & Invoice"),
("sale_and_invoice_draft", "Sale order & Invoice Draft"),
("sale_and_invoice_send", "Sale Order & Invoice Send"),
("sale_draft", "Sale Order Draft"),
("sale_confirmed", "Sale Order Confirmed"),
],
)
code = fields.Char()
Expand Down

0 comments on commit a41e59c

Please sign in to comment.