Skip to content

Commit

Permalink
[14.0][ADD] purchase_invoice_plan_deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu authored and Saran440 committed Feb 21, 2023
1 parent 6d6262d commit cda0061
Show file tree
Hide file tree
Showing 20 changed files with 932 additions and 0 deletions.
98 changes: 98 additions & 0 deletions purchase_invoice_plan_deposit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
==============================================
Purchase Invoice Plan - Deposit on 1st invoice
==============================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/purchase-workflow/tree/15.0/purchase_invoice_plan_deposit
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_invoice_plan_deposit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/142/15.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module bridge features from purchase_invoice_plan and purchase_deposit.
Now, it posssible create invoice plan with 1st invoice as a deposit invoice.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Usage
=====

- Create new purchase quotation as per normal process
- Select option "Use Invoice Plan", a new Invoice Plan tab will appear
- Click on "=> Create Invoice Plan" link to open invoice planning wizard
- Do plan for number of installment and/or **Deposit on 1st invoice**, start date and interval
- Double check that each installment has correct plan percentage (Deposit's plan percentage must > 0)
- After confirm purchases order, we have new option to "Create Bill by Plan"
- User can create only next bill or create all bills at the same time

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_invoice_plan_deposit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Ecosoft

Contributors
~~~~~~~~~~~~

* Kitti Upariphutthiphong <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-kittiu| image:: https://github.com/kittiu.png?size=40px
:target: https://github.com/kittiu
:alt: kittiu

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-kittiu|

This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/15.0/purchase_invoice_plan_deposit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions purchase_invoice_plan_deposit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import models
from . import wizard
21 changes: 21 additions & 0 deletions purchase_invoice_plan_deposit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

{
"name": "Purchase Invoice Plan - Deposit on 1st invoice",
"summary": "Add to purchase invoice plan, the deposit invoice",
"version": "14.0.1.0.0",
"author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/purchase-workflow",
"category": "Purchase",
"depends": ["purchase_invoice_plan", "purchase_deposit"],
"data": [
"wizard/purchase_create_invoice_plan_view.xml",
"views/purchase_view.xml",
],
"installable": True,
"auto_install": True,
"maintainers": ["kittiu"],
"development_status": "Alpha",
}
4 changes: 4 additions & 0 deletions purchase_invoice_plan_deposit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import purchase
98 changes: 98 additions & 0 deletions purchase_invoice_plan_deposit/models/purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import _, api, fields, models
from odoo.exceptions import UserError


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

need_advance = fields.Boolean(
compute="_compute_need_advance",
help="True if use 1st deposit invoice plan, but no deposit yet",
)

@api.constrains("invoice_plan_ids")
def _check_invoice_plan_ids(self):
for rec in self:
for plan in rec.invoice_plan_ids:
if plan.invoice_type == "advance" and plan.installment != 0:
raise UserError(_("Only installment 0 can be of type 'Deposit'"))

def _compute_ip_invoice_plan(self):
"""With case advance in place, do overwrite"""
for rec in self:
has_invoice_plan = rec.use_invoice_plan and rec.invoice_plan_ids
to_invoice = rec.invoice_plan_ids.filtered(lambda l: not l.invoiced)
if rec.state == "purchase" and has_invoice_plan and to_invoice:
if rec.invoice_status == "to invoice" or (
rec.invoice_status == "no"
and "advance" in to_invoice.mapped("invoice_type")
):
rec.ip_invoice_plan = True
continue
rec.ip_invoice_plan = False

def create_invoice_plan(
self, num_installment, installment_date, interval, interval_type
):
advance = self.env.context.get("advance")
advance_percent = self.env.context.get("advance_percent")
advance_date = installment_date
if advance: # installment_date will be after advance_date
installment_date = self._next_date(advance_date, interval, interval_type)
# Call super to create non-advance installments
res = super().create_invoice_plan(
num_installment, installment_date, interval, interval_type
)
# Advance
if advance:
vals = {
"installment": 0,
"plan_date": advance_date,
"invoice_type": "advance",
"percent": advance_percent,
}
self.write({"invoice_plan_ids": [(0, 0, vals)]})
return res

def _compute_need_advance(self):
for order in self:
advance = order.invoice_plan_ids.filtered_domain(
[("invoice_type", "=", "advance")]
)
deposit = order.order_line.filtered("is_deposit")
order.need_advance = advance and not deposit

def action_create_invoice(self):
"""If there is deposit installment, and no invoice is_deposit yet.
Give user a warning.
"""
if self.filtered("need_advance"):
raise UserError(
_("Invoice plan requires deposit, please register deposit first.")
)
return super().action_create_invoice()


class PurchaseInvoicePlan(models.Model):
_inherit = "purchase.invoice.plan"

invoice_type = fields.Selection(
selection_add=[("advance", "Deposit")],
ondelete={"advance": "cascade"},
)

def _update_new_quantity(self, line, percent):
if line.purchase_line_id.is_deposit: # based on 1 unit
line.write({"quantity": -percent / 100})
return
super()._update_new_quantity(line, percent)

def _get_amount_invoice(self, invoices):
"""Override _get_amount_invoice"""
lines = invoices.mapped("invoice_line_ids").filtered(
lambda l: not l.purchase_line_id.is_deposit
)
return sum(lines.mapped("price_subtotal"))
1 change: 1 addition & 0 deletions purchase_invoice_plan_deposit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Kitti Upariphutthiphong <[email protected]>
2 changes: 2 additions & 0 deletions purchase_invoice_plan_deposit/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module bridge features from purchase_invoice_plan and purchase_deposit.
Now, it posssible create invoice plan with 1st invoice as a deposit invoice.
7 changes: 7 additions & 0 deletions purchase_invoice_plan_deposit/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Create new purchase quotation as per normal process
- Select option "Use Invoice Plan", a new Invoice Plan tab will appear
- Click on "=> Create Invoice Plan" link to open invoice planning wizard
- Do plan for number of installment and/or **Deposit on 1st invoice**, start date and interval
- Double check that each installment has correct plan percentage (Deposit's plan percentage must > 0)
- After confirm purchases order, we have new option to "Create Bill by Plan"
- User can create only next bill or create all bills at the same time
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit cda0061

Please sign in to comment.