-
Notifications
You must be signed in to change notification settings - Fork 6
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] sustainability_purchase: product's supplier emission factor preceding order #223
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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
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,28 @@ | ||
from odoo import api, models | ||
|
||
|
||
class ProductSupplierInfo(models.Model): | ||
_name = "product.supplierinfo" | ||
_inherit = ["product.supplierinfo", "carbon.mixin"] | ||
|
||
def _update_carbon_in_fields(self, vals): | ||
""" | ||
Helper method to update carbon_in_is_manual and carbon_in_mode based on carbon_in_factor_id. | ||
""" | ||
if vals.get("carbon_in_factor_id"): | ||
vals["carbon_in_is_manual"] = True | ||
vals["carbon_in_mode"] = "manual" | ||
else: | ||
vals["carbon_in_is_manual"] = False | ||
vals["carbon_in_mode"] = "auto" | ||
return vals | ||
|
||
@api.model | ||
def create(self, vals): | ||
vals = self._update_carbon_in_fields(vals) | ||
return super().create(vals) | ||
|
||
def write(self, vals): | ||
if "carbon_in_factor_id" in vals: | ||
vals = self._update_carbon_in_fields(vals) | ||
return super().write(vals) |
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
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
from . import test_conversion | ||
from . import test_vendors_bill | ||
from . import test_action |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from datetime import datetime | ||
|
||
from odoo import Command | ||
from odoo.tests import TransactionCase | ||
|
||
|
||
|
@@ -116,3 +117,100 @@ def setUpClass(cls): | |
"groups_id": [(6, 0, [cls.env.ref("base.group_user").id])], | ||
} | ||
) | ||
cls.setUpClassVendor() | ||
|
||
@classmethod | ||
def setUpClassVendor(cls): | ||
# Vendor Bills Related | ||
# Vendor Carbon Factors | ||
cls.vendor_carbon_factor_vendor_1 = cls.env["carbon.factor"].create( | ||
dict( | ||
name="Vendor Carbon Factor 1 (VENDOR)", | ||
carbon_compute_method="monetary", | ||
value_ids=[ | ||
Command.create( | ||
dict( | ||
date=datetime.today().strftime("%Y-%m-%d %H:%M"), | ||
carbon_monetary_currency_id=cls.currency_usd.id, | ||
carbon_value=5, | ||
) | ||
) | ||
], | ||
) | ||
) | ||
cls.vendor_carbon_factor_product_1 = cls.env["carbon.factor"].create( | ||
dict( | ||
name="Vendor Carbon Factor 1 (PRODUCT)", | ||
carbon_compute_method="monetary", | ||
value_ids=[ | ||
Command.create( | ||
dict( | ||
date=datetime.today().strftime("%Y-%m-%d %H:%M"), | ||
carbon_monetary_currency_id=cls.currency_usd.id, | ||
carbon_value=10, | ||
) | ||
) | ||
], | ||
) | ||
) | ||
# Vendor Partner | ||
cls.vendor_partner_1 = cls.env["res.partner"].create( | ||
dict( | ||
name="Vendor Partner 1", | ||
email="[email protected]", | ||
phone="+123456789", | ||
street="123 Vendor Street", | ||
city="Vendor City", | ||
country_id=cls.env.ref("base.us").id, | ||
carbon_in_factor_id=cls.vendor_carbon_factor_vendor_1.id, | ||
) | ||
) | ||
|
||
# Vendor Product Category | ||
cls.vendor_product_category_1 = cls.env["product.category"].create( | ||
dict( | ||
name="Vendor Product Category 1", | ||
) | ||
) | ||
# Vendor Product Template | ||
cls.vendor_product_template_1 = cls.env["product.template"].create( | ||
dict( | ||
name="Vendor Product 1", | ||
categ_id=cls.vendor_product_category_1.id, | ||
list_price=100.0, | ||
carbon_in_factor_id=cls.vendor_carbon_factor_product_1.id, | ||
seller_ids=[ | ||
Command.create( | ||
dict( | ||
currency_id=cls.currency_usd.id, | ||
delay=0, | ||
min_qty=1, | ||
partner_id=cls.vendor_partner_1.id, | ||
price=100, | ||
) | ||
) | ||
], | ||
) | ||
) | ||
# Vendor Product Product | ||
cls.vendor_product_product_1 = cls.env["product.product"].search( | ||
[("product_tmpl_id", "=", cls.vendor_product_template_1.id)], limit=1 | ||
) | ||
# Vendor Account Move | ||
cls.vendor_account_move = cls.env["account.move"] | ||
cls.vendor_account_move_1 = cls.env["account.move"].create( | ||
dict( | ||
move_type="in_invoice", | ||
partner_id=cls.vendor_partner_1.id, | ||
invoice_date=datetime.today().strftime("%Y-%m-%d"), | ||
invoice_line_ids=[ | ||
Command.create( | ||
dict( | ||
product_id=cls.vendor_product_product_1.id, | ||
quantity=10.0, | ||
) | ||
) | ||
], | ||
) | ||
) | ||
cls.vendor_account_move |= cls.vendor_account_move_1 |
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.
This is not optimized because it triggers recompute on all account.move.line when you change your seller_ids or the product. Same for company lock date.