Skip to content

[18.0][MIG] sale_margin_sync: Migration to 18.0 #236

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

Open
wants to merge 21 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
693183c
[11.0][ADD] sale_margin_sync: Recompute sale margin when related stoc…
carlosdauden Oct 29, 2019
a66454a
[MIG] sale_margin_sync: Migration to 12.0
carlosdauden Oct 30, 2019
96a531a
[IMP] sale_margin_sync: Create a pricelist for testing to avoid crash…
sergio-teruel Nov 21, 2019
db8eb73
[IMP] sale_margin_sync: black, isort
sergio-teruel Sep 17, 2020
ff233af
[MIG] sale_margin_sync: Migration to v13.0
sergio-teruel Sep 17, 2020
9bf322f
[IMP] sale_margin_sync: Sync sale line purchase price from stock valu…
sergio-teruel Aug 30, 2021
753c699
[IMP] sale_margin_sync: black, isort, prettier
rafamarpe Oct 15, 2022
b4b0cbb
[MIG] sale_margin_sync: Migration to 14.0
rafamarpe Oct 15, 2022
d9eae2b
[MIG] sale_margin_sync: Migration to 15.0
CarlosRoca13 Nov 23, 2022
6f4c9a7
[MIG] sale_margin_sync: Migration to 16.0
Yadier-Tecnativa Apr 17, 2023
3b068db
[UPD] Update sale_margin_sync.pot
Apr 20, 2023
7d799d7
[UPD] README.rst
OCA-git-bot Apr 20, 2023
40ac4b1
Added translation using Weblate (Spanish)
Ivorra78 Aug 21, 2023
027c587
Translated using Weblate (Spanish)
Ivorra78 Aug 21, 2023
2dbb11f
[UPD] README.rst
OCA-git-bot Sep 3, 2023
1855c1b
[IMP] sale_margin_sync: test performance improvement
josep-tecnativa Oct 20, 2023
45d01ef
[BOT] post-merge updates
OCA-git-bot Oct 23, 2023
c070a0e
Added translation using Weblate (Italian)
mymage Jan 22, 2024
324b510
Translated using Weblate (Italian)
mymage Jan 29, 2024
dc9789b
[IMP] sale_margin_sync: pre-commit auto fixes
BhaveshHeliconia Feb 17, 2025
314f766
[MIG] sale_margin_sync: Migration to 18.0
BhaveshHeliconia Feb 17, 2025
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
84 changes: 84 additions & 0 deletions sale_margin_sync/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
================
Sale margin sync
================

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

.. |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-OCA%2Fmargin--analysis-lightgray.png?logo=github
:target: https://github.com/OCA/margin-analysis/tree/18.0/sale_margin_sync
:alt: OCA/margin-analysis
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/margin-analysis-18-0/margin-analysis-18-0-sale_margin_sync
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/margin-analysis&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Recompute sale margin when related stock move cost price is changed.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/margin-analysis/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/OCA/margin-analysis/issues/new?body=module:%20sale_margin_sync%0Aversion:%2018.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
-------

* Tecnativa

Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:

- Carlos Dauden
- Sergio Teruel
- Carlos Roca

- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__

- Bhavesh Heliconia

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/margin-analysis <https://github.com/OCA/margin-analysis/tree/18.0/sale_margin_sync>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions sale_margin_sync/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
13 changes: 13 additions & 0 deletions sale_margin_sync/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale margin sync",
"summary": "Recompute sale margin when stock move cost price is changed",
"version": "18.0.1.0.0",
"category": "Sales",
"website": "https://github.com/OCA/margin-analysis",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["sale_margin", "sale_stock"],
}
22 changes: 22 additions & 0 deletions sale_margin_sync/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_margin_sync
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-09-02 18:17+0000\n"
"Last-Translator: Ivorra78 <[email protected]>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: sale_margin_sync
#: model:ir.model,name:sale_margin_sync.model_stock_valuation_layer
msgid "Stock Valuation Layer"
msgstr "Nivel de valoración de existencias"
22 changes: 22 additions & 0 deletions sale_margin_sync/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_margin_sync
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-01-29 17:38+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: sale_margin_sync
#: model:ir.model,name:sale_margin_sync.model_stock_valuation_layer
msgid "Stock Valuation Layer"
msgstr "Livello valutazione magazzino"
19 changes: 19 additions & 0 deletions sale_margin_sync/i18n/sale_margin_sync.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_margin_sync
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_margin_sync
#: model:ir.model,name:sale_margin_sync.model_stock_valuation_layer
msgid "Stock Valuation Layer"
msgstr ""
3 changes: 3 additions & 0 deletions sale_margin_sync/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import stock_valuation_layer
36 changes: 36 additions & 0 deletions sale_margin_sync/models/stock_valuation_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class StockValuationLayer(models.Model):
_inherit = "stock.valuation.layer"

@api.model_create_multi
def create(self, vals_list):
"""Update purchase price from sale line linked to svl record"""
svls = super().create(vals_list)

Check warning on line 13 in sale_margin_sync/models/stock_valuation_layer.py

View check run for this annotation

Codecov / codecov/patch

sale_margin_sync/models/stock_valuation_layer.py#L13

Added line #L13 was not covered by tests
if not self.env.context.get("skip_sale_margin_sync", False):
svls.filtered("stock_move_id.sale_line_id").sale_margin_sync()
return svls

Check warning on line 16 in sale_margin_sync/models/stock_valuation_layer.py

View check run for this annotation

Codecov / codecov/patch

sale_margin_sync/models/stock_valuation_layer.py#L15-L16

Added lines #L15 - L16 were not covered by tests

def write(self, vals):
res = super().write(vals)

Check warning on line 19 in sale_margin_sync/models/stock_valuation_layer.py

View check run for this annotation

Codecov / codecov/patch

sale_margin_sync/models/stock_valuation_layer.py#L19

Added line #L19 was not covered by tests
if "unit_cost" in vals and not self.env.context.get(
"skip_sale_margin_sync", False
):
self.sale_margin_sync()
return res

Check warning on line 24 in sale_margin_sync/models/stock_valuation_layer.py

View check run for this annotation

Codecov / codecov/patch

sale_margin_sync/models/stock_valuation_layer.py#L23-L24

Added lines #L23 - L24 were not covered by tests

def sale_margin_sync(self):
"""Only synchronize outgoing moves"""
for svl in self.filtered(lambda layer: (layer.quantity < 0.0)):
sale_line_id = svl.stock_move_id.sale_line_id
product_cost = svl.unit_cost

Check warning on line 30 in sale_margin_sync/models/stock_valuation_layer.py

View check run for this annotation

Codecov / codecov/patch

sale_margin_sync/models/stock_valuation_layer.py#L29-L30

Added lines #L29 - L30 were not covered by tests
if sale_line_id.product_uom and sale_line_id.product_uom != svl.uom_id:
product_cost = svl.uom_id._compute_price(

Check warning on line 32 in sale_margin_sync/models/stock_valuation_layer.py

View check run for this annotation

Codecov / codecov/patch

sale_margin_sync/models/stock_valuation_layer.py#L32

Added line #L32 was not covered by tests
product_cost,
sale_line_id.product_uom,
)
sale_line_id.purchase_price = product_cost

Check warning on line 36 in sale_margin_sync/models/stock_valuation_layer.py

View check run for this annotation

Codecov / codecov/patch

sale_margin_sync/models/stock_valuation_layer.py#L36

Added line #L36 was not covered by tests
3 changes: 3 additions & 0 deletions sale_margin_sync/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
7 changes: 7 additions & 0 deletions sale_margin_sync/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- [Tecnativa](https://www.tecnativa.com):

> - Carlos Dauden
> - Sergio Teruel
> - Carlos Roca
- [Heliconia Solutions Pvt. Ltd.](<https://www.heliconia.io>)
- Bhavesh Heliconia
1 change: 1 addition & 0 deletions sale_margin_sync/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Recompute sale margin when related stock move cost price is changed.
Binary file added sale_margin_sync/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading