Skip to content

Commit

Permalink
[MIG] stock_custom_exchange_rate_date: Migration to 17.0
Browse files Browse the repository at this point in the history
The following actions were performed:

- Update language file.
- Migrate stock.move.line according to [1].
- Migrate attrs in views according to [2].
- Improve code by using new native methods.

[1]: odoo/odoo@7dda6bb9
[2]: odoo/odoo#104741
  • Loading branch information
xmglord authored and luisg123v committed Jan 6, 2025
1 parent 35c44ef commit fbee30a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion stock_custom_exchange_rate_date/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Customized Rate Date in Stock",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Vauxoo",
"category": "stock",
"website": "http://www.vauxoo.com/",
Expand Down
2 changes: 1 addition & 1 deletion stock_custom_exchange_rate_date/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0+e\n"
"Project-Id-Version: Odoo Server 17.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-05-19 23:36+0000\n"
"PO-Revision-Date: 2023-05-19 23:36+0000\n"
Expand Down
11 changes: 2 additions & 9 deletions stock_custom_exchange_rate_date/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@ def _get_price_unit(self):
line = self.purchase_line_id
if (
not self.picking_id.exchange_rate_date
or not line
or self.product_id != line.product_id
or line.currency_id == line.company_id.currency_id
or self.origin_returned_move_id
or self._should_ignore_pol_price()
):
return super()._get_price_unit()
price_unit = line.price_unit
if line.taxes_id:
price_unit = line.taxes_id.with_context(round=False).compute_all(
price_unit, currency=line.currency_id, quantity=1.0
)["total_excluded"]
if line.product_uom.id != line.product_id.uom_id.id:
price_unit *= line.product_uom.factor / line.product_id.uom_id.factor
price_unit = line._get_gross_price_unit()
price_unit = line.currency_id._convert(
price_unit, line.company_id.currency_id, line.company_id, self.picking_id.exchange_rate_date, round=False
)
Expand Down
1 change: 0 additions & 1 deletion stock_custom_exchange_rate_date/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class StockPicking(models.Model):
_inherit = "stock.picking"

exchange_rate_date = fields.Date(
states={"done": [("readonly", True)], "cancel": [("readonly", True)]},
copy=False,
help="If set, specifies a customized date that will be used when "
"computing product unit prices, instead of the date when the transfer "
Expand Down
5 changes: 3 additions & 2 deletions stock_custom_exchange_rate_date/tests/test_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setUpClass(cls):
cls.vendor = cls.env.ref("base.res_partner_1")
cls.usd = cls.env.ref("base.USD")
cls.eur = cls.env.ref("base.EUR")
cls.eur.active = True
cls.today = fields.Date.context_today(cls.env.user)
cls.yesterday = cls.today - timedelta(days=1)
account = cls.env["account.account"].create(
Expand Down Expand Up @@ -137,7 +138,7 @@ def test_01_date_rate_set(self):
# Set custom rate date on the receipt transfer and confirm
picking_po = po.picking_ids
picking_po.exchange_rate_date = self.yesterday
picking_po.move_line_ids.write({"qty_done": 1.0})
picking_po.move_line_ids.write({"quantity": 1.0})
picking_po.button_validate()
self.assertEqual(picking_po.state, "done")

Expand Down Expand Up @@ -166,7 +167,7 @@ def test_02_date_rate_not_set(self):

# Confirm receipt transfer
picking_po = po.picking_ids
picking_po.move_line_ids.write({"qty_done": 1.0})
picking_po.move_line_ids.write({"quantity": 1.0})
picking_po.button_validate()
self.assertEqual(picking_po.state, "done")

Expand Down
5 changes: 3 additions & 2 deletions stock_custom_exchange_rate_date/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<field name="inherit_id" ref="stock.view_picking_form" />
<field name="arch" type="xml">
<xpath expr="//label[@for='scheduled_date']" position="before">
<field name="purchase_id" invisible="1" />
<field name="purchase_id" invisible="True" />
<field
name="exchange_rate_date"
attrs="{'invisible': ['|', ('purchase_id', '=', False), ('picking_type_code', '!=', 'incoming')]}"
invisible="not purchase_id or picking_type_code != 'incoming'"
readonly="state in ['cancel', 'done']"
/>
</xpath>
</field>
Expand Down

0 comments on commit fbee30a

Please sign in to comment.