-
Notifications
You must be signed in to change notification settings - Fork 29
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
ADD account_stock_situation #308
Open
bealdav
wants to merge
5
commits into
16.0
Choose a base branch
from
stock-valuation
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
71b42c8
ADD account_stock_situation
bealdav 3b0ce57
[IMP] _get_stock_valuation_another function to add the quantity in st…
mathieudelva 66a2cfc
[UPD] change following code review
mathieudelva aa0da11
FIX aac_stk_situation: in _get_stock_valuation()
bealdav e8bbcea
wip
bealdav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,67 @@ | ||
======================= | ||
Account Stock Situation | ||
======================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:17a4d0785da8b351798bf3c7d2b0463b8a22bf996209b21ecc9043ea00b9bfce | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |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-akretion%2Fak--odoo--incubator-lightgray.png?logo=github | ||
:target: https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_stock_situation | ||
:alt: akretion/ak-odoo-incubator | ||
|
||
|badge1| |badge2| |badge3| | ||
|
||
Generate Periodically a miscellaneous account move for stock valuation with an xlsx report attachement | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
Consider to check your report before validate your account move and reverse the previous one. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/akretion/ak-odoo-incubator/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/akretion/ak-odoo-incubator/issues/new?body=module:%20account_stock_situation%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 | ||
~~~~~~~ | ||
|
||
* Akretion | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Akretion | ||
* David BEAL <[email protected]> | ||
* Mathieu DELVA <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is part of the `akretion/ak-odoo-incubator <https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_stock_situation>`_ project on GitHub. | ||
|
||
You are welcome to 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 @@ | ||
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,19 @@ | ||
# Copyright 2024 David BEAL @ akretion | ||
{ | ||
"name": "Account Stock Situation", | ||
"version": "16.0.1.0.0", | ||
"author": "Akretion", | ||
"website": "https://github.com/akretion/ak-odoo-incubator", | ||
"license": "AGPL-3", | ||
"category": "Accounting", | ||
"depends": [ | ||
"account", | ||
"stock", | ||
], | ||
"data": [ | ||
"views/config_settings.xml", | ||
"views/action.xml", | ||
], | ||
"external_dependencies": {"python": ["polars"]}, | ||
"installable": 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,2 @@ | ||
from . import company | ||
from . import config_settings |
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,133 @@ | ||
import base64 | ||
import io | ||
from collections import defaultdict | ||
|
||
import polars as pl | ||
|
||
from odoo import fields, models, tools | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
valued_warehouse_ids = fields.Many2many( | ||
comodel_name="stock.warehouse", | ||
domain=lambda self: [("company_id", "=", self.env.company.id)], | ||
) | ||
stock_journal_id = fields.Many2one(comodel_name="account.journal") | ||
cost_vs_purchase_threshold = fields.Integer(string="Seuil en %") | ||
account_purchase_stock_id = fields.Many2one(comodel_name="account.account") | ||
account_stock_id = fields.Many2one(comodel_name="account.account") | ||
|
||
def _set_account_stock_valuation(self, company_string_id): | ||
self = self.env.ref(company_string_id) | ||
value, attach = self._get_stock_valuation() | ||
for mfield in ( | ||
"account_stock_id", | ||
"account_purchase_stock_id", | ||
"stock_journal_id", | ||
): | ||
if not self[mfield]: | ||
raise UserError( | ||
f"Le champ '{mfield}' n'est pas défini: vérifiez les " | ||
"paramètres intitulés 'Valorisation de stock'" | ||
) | ||
move = self.env["account.move"].create( | ||
{ | ||
"journal_id": self.stock_journal_id.id, | ||
"company_id": self.id, | ||
"to_check": True, | ||
"move_type": "entry", | ||
"line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"account_id": self.account_stock_id.id, | ||
"name": "stock", | ||
"debit": 0, | ||
"credit": value, | ||
}, | ||
), | ||
( | ||
0, | ||
0, | ||
{ | ||
"account_id": self.account_purchase_stock_id.id, | ||
"name": "stock", | ||
"debit": value, | ||
"credit": 0, | ||
}, | ||
), | ||
], | ||
} | ||
) | ||
attach.res_id = move.id | ||
|
||
def _get_stock_valuation(self): | ||
self.ensure_one() | ||
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url") | ||
if tools.config.get("running_env") == "dev": | ||
base_url = "http://anothercorp.localhost/" | ||
location_ids = [x.lot_stock_id.id for x in self.valued_warehouse_ids] | ||
stock_quant_ids = self.env["stock.quant"].search( | ||
[("location_id", "child_of", location_ids)], | ||
) | ||
products = self.env["product.product"].browse(stock_quant_ids.product_id.ids) | ||
vals = defaultdict(list) | ||
product_dict = {} | ||
for stock_quant in stock_quant_ids: | ||
if stock_quant.product_id.id not in product_dict: | ||
product_dict[stock_quant.product_id.id] = [ | ||
stock_quant.warehouse_id, | ||
stock_quant.quantity, | ||
] | ||
else: | ||
if ( | ||
stock_quant.warehouse_id | ||
in product_dict.get(stock_quant.product_id.id)[0] | ||
): | ||
product_dict[stock_quant.product_id.id][1] += stock_quant.quantity | ||
else: | ||
product_dict[stock_quant.product_id.id] += [ | ||
stock_quant.warehouse_id, | ||
stock_quant.quantity, | ||
] | ||
for product_id, warehouse_quantities in product_dict.items(): | ||
product = products.filtered(lambda s: s.id == product_id) | ||
vals["link"].append( | ||
f"{base_url}/web#id={product_id}&cids={self.id}&action=" | ||
f"{self.env.ref('product.product_normal_action_sell').id}&model=" | ||
"product.product&view_type=form" | ||
) | ||
vals["code"].append(product.default_code) | ||
vals["designation"].append(product.name) | ||
for i in range(0, len(warehouse_quantities), 2): | ||
warehouse_id = warehouse_quantities[i] | ||
quantity = warehouse_quantities[i + 1] | ||
vals[f"qty_{warehouse_id.code}"].append(round(quantity)) | ||
if len(warehouse_quantities) / 2 < len(self.valued_warehouse_ids): | ||
warehouse_without_qty = self.valued_warehouse_ids.filtered( | ||
lambda r: r.id | ||
not in [ | ||
warehouse_quantities[i].id | ||
for i in range(0, len(warehouse_quantities), 2) | ||
] | ||
) | ||
for warehouse in warehouse_without_qty: | ||
vals[f"qty_{warehouse.code}"].append(0) | ||
|
||
vals["value"].append(round(product.standard_price, 2)) | ||
df = pl.from_dict(vals) | ||
mfile = io.BytesIO() | ||
df.write_excel(workbook=mfile) | ||
attach = self.env["ir.attachment"].create( | ||
{ | ||
"name": "Valorisation_stock_jourdain", | ||
"type": "binary", | ||
"res_model": "account.move", | ||
"datas": base64.b64encode(mfile.getvalue()), | ||
} | ||
) | ||
return sum(vals["value"]), attach |
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,37 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
valued_warehouse_ids = fields.Many2many( | ||
related="company_id.valued_warehouse_ids", readonly=False | ||
) | ||
cost_vs_purchase_threshold = fields.Integer( | ||
related="company_id.cost_vs_purchase_threshold", readonly=False, default=120 | ||
) | ||
stock_journal_id = fields.Many2one( | ||
comodel_name="account.journal", | ||
readonly=False, | ||
related="company_id.stock_journal_id", | ||
domain=[("type", "=", "general")], | ||
) | ||
account_purchase_stock_id = fields.Many2one( | ||
comodel_name="account.account", | ||
readonly=False, | ||
related="company_id.account_purchase_stock_id", | ||
) | ||
account_stock_id = fields.Many2one( | ||
comodel_name="account.account", | ||
readonly=False, | ||
related="company_id.account_stock_id", | ||
) | ||
account_stock_help = fields.Text(compute="_compute_account_stock_help") | ||
|
||
def _compute_account_stock_help(self): | ||
for rec in self: | ||
name = "" | ||
if "l10n_fr" in self.env.registry._init_modules: | ||
name = "Compte de stock: '355...'" | ||
name += "Compte de stock d'achat: '603...'" | ||
rec.account_stock_help = name |
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,3 @@ | ||
* Akretion | ||
* David BEAL <[email protected]> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il faut te rajouter ici |
||
* Mathieu DELVA <[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 @@ | ||
Generate Periodically a miscellaneous account move for stock valuation with an xlsx report attachement |
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 @@ | ||
Consider to check your report before validate your account move and reverse the previous one. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Du coup je ne pense pas kil faut utiliser le read_group vu que c pas top de stocker le warehouse ds les locations.
Tu pourrais modifier la PR en ce sens ?