-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] account_cutoff_accrual_purchase_stock
- Loading branch information
Showing
13 changed files
with
1,054 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
====================================== | ||
Account Cut-off Accrual Purchase Stock | ||
====================================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:a38a09f71438e61874c41e5707f0d98e49c5fe9b87cfaadbbcd2e31a0f9ca227 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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-OCA%2Faccount--closing-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account-closing/tree/16.0/account_cutoff_accrual_purchase_stock | ||
:alt: OCA/account-closing | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/account-closing-16-0/account-closing-16-0-account_cutoff_accrual_purchase_stock | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-closing&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module extends the functionality of account_cutoff_accrual_purchase | ||
to allow the computation of expense cutoffs on purchase orders for storable products. | ||
|
||
This glue module allows to detect the quantities received after the cutoff date. | ||
|
||
See account_cutoff_accrual_purchase for more explanations. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-closing/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/OCA/account-closing/issues/new?body=module:%20account_cutoff_accrual_purchase_stock%0Aversion:%2016.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 | ||
~~~~~~~ | ||
|
||
* BCIM | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Jacques-Etienne Baudoux (BCIM) <[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-jbaudoux| image:: https://github.com/jbaudoux.png?size=40px | ||
:target: https://github.com/jbaudoux | ||
:alt: jbaudoux | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-jbaudoux| | ||
|
||
This module is part of the `OCA/account-closing <https://github.com/OCA/account-closing/tree/16.0/account_cutoff_accrual_purchase_stock>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
{ | ||
"name": "Account Cut-off Accrual Purchase Stock", | ||
"version": "16.0.1.0.0", | ||
"category": "Accounting & Finance", | ||
"license": "AGPL-3", | ||
"summary": "Accrued Order Base", | ||
"author": "BCIM, Odoo Community Association (OCA)", | ||
"maintainers": ["jbaudoux"], | ||
"website": "https://github.com/OCA/account-closing", | ||
"depends": [ | ||
"account_cutoff_accrual_purchase", | ||
"account_cutoff_accrual_order_stock_base", | ||
"purchase_stock", | ||
], | ||
"installable": True, | ||
"application": False, | ||
"auto_install": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import purchase_order_line |
74 changes: 74 additions & 0 deletions
74
account_cutoff_accrual_purchase_stock/models/purchase_order_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright 2018 Jacques-Etienne Baudoux (BCIM sprl) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
from odoo import models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_name = "purchase.order.line" | ||
_inherit = ["purchase.order.line"] | ||
|
||
def _get_cutoff_accrual_lines_delivered_after(self, cutoff): | ||
lines = super()._get_cutoff_accrual_lines_delivered_after(cutoff) | ||
cutoff_nextday = cutoff._nextday_start_dt() | ||
# Take all moves done after the cutoff date | ||
# In SQL to reduce memory usage as we could process large dataset | ||
self.env.cr.execute( | ||
""" | ||
SELECT order_id | ||
FROM purchase_order_line | ||
WHERE id in ( | ||
SELECT purchase_line_id | ||
FROM stock_move | ||
WHERE state='done' | ||
AND date >= %s | ||
AND sale_line_id IS NOT NULL | ||
) | ||
""", | ||
(cutoff_nextday,), | ||
) | ||
purchase_ids = [x[0] for x in self.env.cr.fetchall()] | ||
lines = self.env["purchase.order.line"].search( | ||
["|", ("order_id", "in", purchase_ids), ("id", "in", lines.ids)], order="id" | ||
) | ||
return lines | ||
|
||
def _get_cutoff_accrual_delivered_min_date(self): | ||
"""Return first delivery date""" | ||
self.ensure_one() | ||
stock_moves = self.move_ids.filtered(lambda m: m.state == "done") | ||
if not stock_moves: | ||
return | ||
return min(stock_moves.mapped("date")).date() | ||
|
||
def _get_cutoff_accrual_delivered_stock_quantity(self, cutoff): | ||
self.ensure_one() | ||
cutoff_nextday = cutoff._nextday_start_dt() | ||
if self.create_date >= cutoff_nextday: | ||
# A line added after the cutoff cannot be received in the past | ||
return 0 | ||
received_qty = self.qty_received | ||
# The quantity received on the PO line must be deducted from all | ||
# moves done after the cutoff date. | ||
out_moves, in_moves = self._get_outgoing_incoming_moves() | ||
for move in out_moves: | ||
if move.state != "done" or move.date < cutoff_nextday: | ||
continue | ||
received_qty += move.product_uom._compute_quantity( | ||
move.product_uom_qty, | ||
self.product_uom, | ||
rounding_method="HALF-UP", | ||
) | ||
for move in in_moves: | ||
if move.state != "done" or move.date < cutoff_nextday: | ||
continue | ||
received_qty -= move.product_uom._compute_quantity( | ||
move.product_uom_qty, | ||
self.product_uom, | ||
rounding_method="HALF-UP", | ||
) | ||
return received_qty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Jacques-Etienne Baudoux (BCIM) <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This module extends the functionality of account_cutoff_accrual_purchase | ||
to allow the computation of expense cutoffs on purchase orders for storable products. | ||
|
||
This glue module allows to detect the quantities received after the cutoff date. | ||
|
||
See account_cutoff_accrual_purchase for more explanations. |
Oops, something went wrong.