Skip to content

Commit

Permalink
[16.0][ADD] purchase_sale_lot_intercompany
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev-Roche committed Jan 30, 2024
1 parent 141616a commit c56040e
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 0 deletions.
1 change: 1 addition & 0 deletions purchase_sale_lot_intercompany/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions purchase_sale_lot_intercompany/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Purchase Sale Lot Intercompany",
"summary": "Intercompany PO/SO lot number propagation",
"version": "16.0.1.0.0",
"category": "Purchase Management",
"website": "https://github.com/OCA/multi-company",
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["Kev-Roche"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"purchase_lot",
"purchase_sale_inter_company",
],
"data": [
"views/res_config_settings_views.xml",
],
}
77 changes: 77 additions & 0 deletions purchase_sale_lot_intercompany/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_sale_lot_intercompany
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-13 18:52+0000\n"
"PO-Revision-Date: 2023-03-13 19:54+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 3.2.2\n"

#. module: purchase_sale_lot_intercompany
#: model:ir.model,name:purchase_sale_lot_intercompany.model_res_company
msgid "Companies"
msgstr "Sociétés"

#. module: purchase_sale_lot_intercompany
#: model:ir.model,name:purchase_sale_lot_intercompany.model_res_config_settings
msgid "Config Settings"
msgstr "Paramètres de config"

#. module: purchase_sale_lot_intercompany
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_purchase_order__display_name
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_res_company__display_name
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_res_config_settings__display_name
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_stock_production_lot__display_name
msgid "Display Name"
msgstr "Nom affiché"

#. module: purchase_sale_lot_intercompany
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_purchase_order__id
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_res_company__id
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_res_config_settings__id
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_stock_production_lot__id
msgid "ID"
msgstr ""

#. module: purchase_sale_lot_intercompany
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_purchase_order____last_update
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_res_company____last_update
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_res_config_settings____last_update
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_stock_production_lot____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"

#. module: purchase_sale_lot_intercompany
#: model:ir.model,name:purchase_sale_lot_intercompany.model_stock_production_lot
msgid "Lot/Serial"
msgstr "Lot/N° série"

#. module: purchase_sale_lot_intercompany
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_res_company__propagated_serial_number
msgid "Lots/Serial Numbers are propogated in this company"
msgstr "Lot/N° série copiés dans cette société"

#. module: purchase_sale_lot_intercompany
#: model:ir.model.fields,field_description:purchase_sale_lot_intercompany.field_res_config_settings__propagated_serial_number
msgid "Lots/Serial Numbers propagated in sale"
msgstr "Lot/N° série copiés dans les commandes de ventes"

#. module: purchase_sale_lot_intercompany
#: model_terms:ir.ui.view,arch_db:purchase_sale_lot_intercompany.res_config_settings_view_form
msgid "Propagated Lots from purchase to sale"
msgstr "Lot/N° série copiés des achats vers les commandes de ventes de cette société"

#. module: purchase_sale_lot_intercompany
#: model:ir.model,name:purchase_sale_lot_intercompany.model_purchase_order
msgid "Purchase Order"
msgstr "Commande fournisseur"
4 changes: 4 additions & 0 deletions purchase_sale_lot_intercompany/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import purchase_order
from . import stock_production_lot
from . import res_company
from . import res_config_settings
18 changes: 18 additions & 0 deletions purchase_sale_lot_intercompany/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <[email protected]>
# @author Guillaume MASSON <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

def _prepare_sale_order_line_data(self, purchase_line, dest_company, sale_order):
vals = super()._prepare_sale_order_line_data(
purchase_line, dest_company, sale_order
)
if dest_company.propagated_serial_number and purchase_line.lot_id:
vals["lot_id"] = purchase_line.lot_id.get_inter_company_lot(dest_company).id
return vals
14 changes: 14 additions & 0 deletions purchase_sale_lot_intercompany/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <[email protected]>
# @author Guillaume MASSON <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

propagated_serial_number = fields.Boolean(
string="Lots/Serial Numbers are propogated in this company"
)
16 changes: 16 additions & 0 deletions purchase_sale_lot_intercompany/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <[email protected]>
# @author Guillaume MASSON <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

propagated_serial_number = fields.Boolean(
string="Lots/Serial Numbers propagated in sale",
related="company_id.propagated_serial_number",
readonly=False,
)
29 changes: 29 additions & 0 deletions purchase_sale_lot_intercompany/models/stock_production_lot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <[email protected]>
# @author Guillaume MASSON <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class StockProductionLot(models.Model):
_inherit = "stock.lot"

def get_inter_company_lot(self, company):
self.ensure_one()
lot = self.sudo().search(
[
("name", "=", self.name),
("product_id", "=", self.product_id.id),
("company_id", "=", company.id),
]
)
if not lot:
lot = self.sudo().create(
{
"name": self.name,
"product_id": self.product_id.id,
"company_id": company.id,
}
)
return lot
2 changes: 2 additions & 0 deletions purchase_sale_lot_intercompany/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Kévin Roche <[email protected]>
* Guillaume MASSON <[email protected]>
1 change: 1 addition & 0 deletions purchase_sale_lot_intercompany/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to propagate lot numbers from a purchase to a sale line, in a multi-company context.
1 change: 1 addition & 0 deletions purchase_sale_lot_intercompany/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check the "Lots/Serial Numbers propagated in sale"
1 change: 1 addition & 0 deletions purchase_sale_lot_intercompany/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_purchase_sale_lot_intercompany
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Kévin Roche <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.purchase_sale_inter_company.tests.test_inter_company_purchase_sale import (
TestPurchaseSaleInterCompany,
)


class TestPurchaseSaleLotIntercompany(TestPurchaseSaleInterCompany):
@classmethod
def setUpClass(cls):
super().setUpClass()

cls.lot_test = cls.env["stock.lot"].create(
{
"name": "lot_test",
"product_id": cls.product.id,
"company_id": cls.warehouse_a.company_id.id,
}
)
cls.purchase_company_a.order_line[0].lot_id = cls.lot_test

def test_with_propagated_serial_number(self):
self.company_b.propagated_serial_number = True
sale = self._approve_po()
self.assertEqual(sale.order_line[0].lot_id.name, "lot_test")

def test_without_propagated_serial_number(self):
sale = self._approve_po()
self.assertFalse(sale.order_line[0].lot_id)
26 changes: 26 additions & 0 deletions purchase_sale_lot_intercompany/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.form.inherit</field>
<field name="model">res.config.settings</field>
<field
name="inherit_id"
ref="purchase_sale_inter_company.res_config_settings_view_form"
/>
<field name="arch" type="xml">
<xpath expr="//div[@id='inter_company_so_from_po']" position="after">
<field
name="propagated_serial_number"
class="oe_inline"
attrs="{'invisible':['|', ('company_id', '=', False), ('so_from_po', '=', False)]}"
/>
<label
string="Propagated Lots in sale from purchase"
class="o_light_label"
for="propagated_serial_number"
attrs="{'invisible':['|', ('company_id', '=', False), ('so_from_po', '=', False)]}"
/>
</xpath>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/purchase_sale_lot_intercompany/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit c56040e

Please sign in to comment.