-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] sustainability*: product's supplier emission factor preceding o…
…rder (#223) - #201 --------- Co-authored-by: Adam Bonnet <[email protected]>
- Loading branch information
Showing
24 changed files
with
929 additions
and
133 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
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.