Skip to content

[17.0][MIG] sale_margin_sync: Migration to 17.0 #241

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 18 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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/17.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-17-0/margin-analysis-17-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=17.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:%2017.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/17.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": "17.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)
if not self.env.context.get("skip_sale_margin_sync", False):
svls.filtered("stock_move_id.sale_line_id").sale_margin_sync()
return svls

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 line: (line.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