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][ADD] egd_purchase_request_custom: add new module #30

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 54 additions & 0 deletions egd_purchase_request_custom/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
===========================
Egd Purchase Request Custom
===========================

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

.. |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-Escodoo%2Fegd--addons-lightgray.png?logo=github
:target: https://github.com/Escodoo/egd-addons/tree/14.0/egd_purchase_request_custom
:alt: Escodoo/egd-addons

|badge1| |badge2| |badge3|


**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/Escodoo/egd-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/Escodoo/egd-addons/issues/new?body=module:%20egd_purchase_request_custom%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
~~~~~~~

* Escodoo

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

This module is part of the `Escodoo/egd-addons <https://github.com/Escodoo/egd-addons/tree/14.0/egd_purchase_request_custom>`_ project on GitHub.

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

{
"name": "Egd Purchase Request Custom",
"summary": """
EGD Purchase Request Custom""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo",
"website": "https://github.com/Escodoo/egd-addons",
"depends": ["purchase_request"],
"data": [
"views/purchase_request_view.xml",
"views/purchase_request_line.xml",
],
}
2 changes: 2 additions & 0 deletions egd_purchase_request_custom/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import purchase_request
from . import purchase_request_line
9 changes: 9 additions & 0 deletions egd_purchase_request_custom/models/purchase_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2023 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class PurchaseRequest(models.Model):

_inherit = "purchase.request"
99 changes: 99 additions & 0 deletions egd_purchase_request_custom/models/purchase_request_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Copyright 2023 - TODAY, Kaynnan Lemes <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class PurchaseRequestLine(models.Model):

_inherit = "purchase.request.line"

estimated_cost = fields.Float(
compute="_compute_egd_estimated_cost", store=True, tracking=True
)

egd_estimated_unit_cost = fields.Float(
string="Estimated Unit Cost",
compute="_compute_egd_estimated_unit_cost",
readonly=False,
store=True,
tracking=True,
)

egd_target_value = fields.Float(
string="Target Unit Price", compute="_compute_egd_target_value"
)

egd_target_above = fields.Boolean(
string="Target Above",
compute="_compute_egd_target_above",
)

@api.depends(
"product_qty",
kaynnan marked this conversation as resolved.
Show resolved Hide resolved
"product_id",
"egd_estimated_unit_cost",
)
def _compute_egd_estimated_cost(self):
"""
Calculate the estimated cost of the purchase request line.
"""
for line in self:
line.estimated_cost = line.product_qty * line.egd_estimated_unit_cost

@api.depends("product_id")
def _compute_egd_estimated_unit_cost(self):
"""
Compute the estimated unit cost based on product's standard price.
"""
for line in self:
if line.product_id:
line.egd_estimated_unit_cost = line.product_id.standard_price
else:
line.egd_estimated_unit_cost = 0.0

@api.depends(
"analytic_account_id",
"egd_estimated_unit_cost",
)
def _compute_egd_target_value(self):
for record in self:
product = False
service = False
price_unit = 0
account_analytic = False
if record.product_id:
if record.analytic_account_id:
account_analytic = record.analytic_account_id
if account_analytic:
purchase_requests = record.env["purchase.request.line"].search(
[("analytic_account_id", "=", account_analytic.id)]
)
if purchase_requests:
product = record.env["product.product"].search(
[("id", "=", record.product_id.id)],
limit=1,
order="write_date desc",
)
service = record.env["product.product"].search(
[("id", "=", record.product_id.id)],
limit=1,
order="write_date desc",
)
if product:
price_unit = product.standard_price
elif service:
price_unit = service.standard_price
record.egd_target_value = price_unit

@api.depends(
"analytic_account_id",
"egd_target_value",
"egd_estimated_unit_cost",
)
def _compute_egd_target_above(self):
for record in self:
target_above = False
if record.egd_estimated_unit_cost > record.egd_target_value:
target_above = True
record.egd_target_above = target_above
Empty file.
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading