Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14.0 account payment term manual 2 #16

Merged
merged 28 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2c394ec
[NEW] account_payment_term_manual
mileo May 26, 2024
ccffa44
[NEW] account_payment_term_manual_sale
mileo May 26, 2024
11af024
[NEW] account_payment_term_manual_purchase
mileo May 26, 2024
837e431
[REF] reformat, fix pre-commit and renames
DiegoParadeda May 29, 2024
a48d05e
[ADD] Compute manual terms
DiegoParadeda Jun 4, 2024
9f9dea8
[FIX] payment_term_id compute order
DiegoParadeda Jun 4, 2024
61f9a80
[FIX] change super call position to fix create problem
DiegoParadeda Jun 5, 2024
3696951
[FIX] dont copy manual terms - breaks duplicate invoice usage
DiegoParadeda Jun 5, 2024
d602795
[WIP] change term manual to term line manual
DiegoParadeda Jun 5, 2024
6ded1b9
[ADD] create invoice specific pay_term and logic
DiegoParadeda Jun 7, 2024
ae65fc2
[ADD] Use new model/table for manual terms
DiegoParadeda Jun 10, 2024
b6f4af1
[FIX] remove payment_id required field for manual term line
DiegoParadeda Jun 10, 2024
74f5c0f
[ADD] payment term manual mixin
DiegoParadeda Jun 10, 2024
a8e92d1
[ADD] payment term manual mixin to sale order
DiegoParadeda Jun 10, 2024
18ecca5
[FIX] conflicting onchange manual term - use constrains
DiegoParadeda Jun 11, 2024
908c131
[RMV] pandoc
DiegoParadeda Jun 11, 2024
c4c4db3
[REF] More representative file name
DiegoParadeda Jun 12, 2024
a45c1e7
[ADD] manual term purchase mixin intergration
DiegoParadeda Jun 12, 2024
0d5ddc2
[ADD] invoice from PO
DiegoParadeda Jun 12, 2024
3907a70
[ADD] invoice from SO
DiegoParadeda Jun 12, 2024
6797976
[ADD] invoice directly - SO/PO recomputes
DiegoParadeda Jun 12, 2024
ffc0034
[REF] better method description
DiegoParadeda Jun 13, 2024
f7ac215
[ADD] invoice onshipping manual term addon
DiegoParadeda Jun 13, 2024
1b97b73
[ADD] fixed date field in manual term line
DiegoParadeda Jun 13, 2024
74f6b83
[ADD] fixed date functionalities
DiegoParadeda Jun 13, 2024
0dc540b
fixup! [ADD] fixed date functionalities
DiegoParadeda Jun 25, 2024
2061685
[FIX] no create_edit for term id
DiegoParadeda Jun 26, 2024
d2f608d
[ADD] manual lines SO/PO validation
DiegoParadeda Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions account_payment_term_manual/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
===================================
Account Invoice Manual Payment Term
===================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:655e2b958eabdd60901deb0de14d723013fe0449da858721037b8e0ccbcc1dd6
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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-KMEE%2Fkmee--odoo--addons-lightgray.png?logo=github
:target: https://github.com/KMEE/kmee-odoo-addons/tree/14.0/account_payment_term_manual
:alt: KMEE/kmee-odoo-addons

|badge1| |badge2| |badge3|

[ This file must be max 2-3 paragraphs, and is required. ]

This module extends the functionality of ... to support ... and to allow
you to ...

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

[ This file is optional but strongly suggested to allow end-users to
evaluate the module's usefulness in their context. ]

It should explain the “why” of the module:

- in which context or use cases this module can be useful (practical
examples are welcome!).
- what is the business requirement that generated the need to develop
this module

It can also inform on related modules:

- modules it depends on and their features
- other modules that can work well together with this one
- suggested setups where the module is useful (eg: multicompany,
multi-website)

Installation
============

[ This file must only be present if there are very specific installation
instructions, such as installing non-python dependencies. The audience
is systems administrators. ]

To install this module, you need to:

1. Do this ...

Configuration
=============

[ This file is optional, it should explain how to configure the module
before using it; it is aimed at advanced users. ]

To configure this module, you need to:

- Go to ...

|alternative description|

.. |alternative description| image:: https://raw.githubusercontent.com/KMEE/kmee-odoo-addons/14.0/account_payment_term_manual/static/description/icon.png

Usage
=====

[ This file must be present and contains the usage instructions for
end-users. As all other rst files included in the README, it MUST NOT
contain reStructuredText sections only body text (paragraphs, lists,
tables, etc). Should you need a more elaborate structure to explain the
addon, please create a Sphinx documentation (which may include this file
as a "quick start" section). ]

To use this module, you need to:

1. Go to ...

Known issues / Roadmap
======================

[ Enumerate known caveats and future potential improvements. It is
mostly intended for end-users, and can also help potential new
contributors discovering new features to implement. ]

Changelog
=========

[ The change log. The goal of this file is to help readers understand
changes between version. The primary audience is end users and
integrators. Purely technical changes such as code refactoring must not
be mentioned here.

This file may contain ONE level of section titles, underlined with the ~
(tilde) character. Other section markers are forbidden and will likely
break the structure of the README.rst or other documents where this
fragment is included. ]

14.0.1.0.0 (2024-05-26)
-----------------------

- Initial commit

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

Bugs are tracked on `GitHub Issues <https://github.com/KMEE/kmee-odoo-addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/KMEE/kmee-odoo-addons/issues/new?body=module:%20account_payment_term_manual%0Aversion:%2014.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
-------

* KMEE

Contributors
------------

- Firstname Lastname [email protected] (optional company
website url)
- Second Person [email protected] (optional company website
url)

Other credits
-------------

[ This file is optional and contains additional credits, other than
authors, contributors, and maintainers. ]

The development of this module has been financially supported by:

- Company 1 name
- Company 2 name

Maintainers
-----------

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

Current maintainer:

|maintainer-mileo|

This module is part of the `KMEE/kmee-odoo-addons <https://github.com/KMEE/kmee-odoo-addons/tree/14.0/account_payment_term_manual>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions account_payment_term_manual/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions account_payment_term_manual/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Account Invoice Manual Payment Term",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "KMEE,Odoo Community Association (OCA)",
"development_status": "Beta",
"maintainers": ["mileo"],
"website": "https://github.com/KMEE/kmee-odoo-addons",
"depends": [
"account_payment_partner",
"l10n_br_account_due_list",
"base_sparse_field",
],
"data": [
"security/payment_term_manual.xml",
"views/account_invoice_view.xml",
"views/account_payment_term_manual_views.xml",
],
}
4 changes: 4 additions & 0 deletions account_payment_term_manual/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import account_payment_term_manual_mixin
from . import account_move
from . import account_payment_term
from . import account_payment_term_manual
55 changes: 55 additions & 0 deletions account_payment_term_manual/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class AccountMove(models.Model):

_name = "account.move"
_inherit = [
"account.move",
"account.payment.term.manual.mixin",
]

@api.onchange(
"line_ids",
"invoice_payment_term_id",
"invoice_date_due",
"invoice_cash_rounding_id",
"invoice_vendor_bill_id",
)
def _onchange_recompute_dynamic_lines(self):
if not self.invoice_payment_term_id:
return super(AccountMove, self)._onchange_recompute_dynamic_lines()
# Replace manual lines if:
# 1. invoice term has changed directly
# 2. invoice term has changed indirectly but no current manual term is set
if (
self.env.context.get("payment_term_id_view_onchange")
or not self.manual_payment_term_id
):
# Unlink and create seem to reset invoice_payment_term_id, here we store it
# in a variable to set the term_id again at the END OF THE METHOD
new_inv_term_id = self.invoice_payment_term_id

# unlinks/creates happen in this method: _update_manual_payment_term_id
self._update_manual_payment_term_id(self.invoice_payment_term_id)

# END OF THE METHOD -> ensure term_id gets set to user defined value
self.invoice_payment_term_id = new_inv_term_id

super(AccountMove, self)._onchange_recompute_dynamic_lines()

def _recompute_payment_terms_lines(self):
return super(
AccountMove,
self.with_context(manual_payment_term_id=self.manual_payment_term_id),
)._recompute_payment_terms_lines()

@api.onchange("manual_payment_term_id")
def _onchange_manual_payment_term_id(self):
self._onchange_recompute_dynamic_lines()

def recompute_payment_lines(self):
self._onchange_recompute_dynamic_lines()
86 changes: 86 additions & 0 deletions account_payment_term_manual/models/account_payment_term.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from dateutil.relativedelta import relativedelta

from odoo import fields, models


class AccountPaymentTerm(models.Model):
_inherit = "account.payment.term"

def compute(self, value, date_ref=False, currency=None):
"""
Inherit compute to use manual term id if set.

manual_payment_term_id must be set
manual_payment_term_id must have manual lines (else just use normal term_id)
if self == manual_payment_term_id there's no need to override this method

complete override for terms with fixed dates > look for alternatives

"""
manual_payment_term_id = self.env.context.get("manual_payment_term_id")
if (
manual_payment_term_id
and manual_payment_term_id.has_manual_lines
and self is not manual_payment_term_id
):
return manual_payment_term_id.compute(
value, date_ref=date_ref, currency=currency
)

if "custom" in self.line_ids.mapped("option"):
# No alternative other than complete method override
# can't call super
return self.compute_override(value, date_ref=date_ref, currency=currency)

return super().compute(value, date_ref=date_ref, currency=currency)

def compute_override(self, value, date_ref=False, currency=None):
"""
Full override of compute method to fixed date manual lines if set.
"""
self.ensure_one()
date_ref = date_ref or fields.Date.context_today(self)
amount = value
sign = value < 0 and -1 or 1
result = []
if not currency and self.env.context.get("currency_id"):
currency = self.env["res.currency"].browse(self.env.context["currency_id"])
elif not currency:
currency = self.env.company.currency_id
for line in self.line_ids:
if line.value == "fixed":
amt = sign * currency.round(line.value_amount)
elif line.value == "percent":
amt = currency.round(value * (line.value_amount / 100.0))
elif line.value == "balance":
amt = currency.round(amount)
next_date = fields.Date.from_string(date_ref)
if line.option == "day_after_invoice_date":
next_date += relativedelta(days=line.days)
if line.day_of_the_month > 0:
months_delta = (line.day_of_the_month < next_date.day) and 1 or 0
next_date += relativedelta(
day=line.day_of_the_month, months=months_delta
)
elif line.option == "after_invoice_month":
next_first_date = next_date + relativedelta(
day=1, months=1
) # Getting 1st of next month
next_date = next_first_date + relativedelta(days=line.days - 1)
elif line.option == "day_following_month":
next_date += relativedelta(day=line.days, months=1)
elif line.option == "day_current_month":
next_date += relativedelta(day=line.days, months=0)
elif line.option == "custom":
next_date = line.fixed_date
result.append((fields.Date.to_string(next_date), amt))
amount -= amt
amount = sum(amt for _, amt in result)
dist = currency.round(value - amount)
if dist:
last_date = result and result[-1][0] or fields.Date.context_today(self)
result.append((last_date, dist))
return sorted(result, key=lambda k: k[0])
Loading
Loading