Skip to content
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

[14.0][REF] l10n_br_sale_stock: Extraction referent the creation of the module sale_stock_picking_invoicing #2955

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions l10n_br_sale_stock/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ No configuration required.
Changelog
=========

14.0.2.0.0 (2024-04-26)
~~~~~~~~~~~~~~~~~~~~~~~
* [REF] Extraction to module sale_stock_picking_invoicing
https://github.com/OCA/account-invoicing/pull/1025

14.0.1.0.0 (2022-09-16)
~~~~~~~~~~~~~~~~~~~~~~~

* [MIG] Migration to version 14.0

12.0.1.0.0 (2020-05-29)
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
9 changes: 2 additions & 7 deletions l10n_br_sale_stock/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@
"license": "AGPL-3",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-brazil",
"version": "14.0.1.4.0",
"version": "14.0.2.0.0",
"maintainers": ["renatonlima", "mbcosta"],
"depends": [
"sale_stock",
"sale_stock_picking_invoicing",
"l10n_br_sale",
"l10n_br_stock_account",
],
"data": [
"views/res_company_view.xml",
"views/res_config_settings_view.xml",
"views/sale_order_view.xml",
],
"demo": [
"demo/l10n_br_sale_stock_demo.xml",
"demo/sale_order_demo.xml",
Expand Down
322 changes: 237 additions & 85 deletions l10n_br_sale_stock/demo/sale_order_demo.xml

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions l10n_br_sale_stock/migrations/14.0.2.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2024-Today - Akretion (<http://www.akretion.com>).
# @author Magno Costa <magno.costa@akretion.com.br>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

_column_renames = {
"res_company": [
("sale_create_invoice_policy", "sale_invoicing_policy"),
],
}


@openupgrade.migrate(use_env=True)
def migrate(env, version):
if openupgrade.column_exists(env.cr, "res_company", "sale_create_invoice_policy"):
openupgrade.logged_query(
env.cr,
"""
UPDATE res_company
SET sale_invoicing_policy = sale_create_invoice_policy;
""",
)

# Apagando campos para evitar mensagem 'HINT ...'
# Deleting field res.company.sale_create_invoice_policy
# (hint: fields should be explicitly removed by an upgrade script)
openupgrade.logged_query(
env.cr,
"""
DELETE FROM ir_model_fields WHERE name = 'sale_create_invoice_policy'
""",
)
openupgrade.logged_query(
env.cr,
"""
DELETE FROM ir_model_fields WHERE name = 'button_create_invoice_invisible'
""",
)
32 changes: 1 addition & 31 deletions l10n_br_sale_stock/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,12 @@
# Copyright (C) 2020 Magno Costa - Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, fields, models
from odoo import api, models


class SaleOrder(models.Model):
_inherit = "sale.order"

# Make Invisible Invoice Button
button_create_invoice_invisible = fields.Boolean(
compute="_compute_get_button_create_invoice_invisible"
)

@api.depends("state", "order_line.invoice_status")
def _compute_get_button_create_invoice_invisible(self):
button_create_invoice_invisible = False

lines = self.order_line.filtered(
lambda line: line.invoice_status == "to invoice"
)

# Somente depois do Pedido confirmado o botão pode aparecer
if self.state != "sale":
button_create_invoice_invisible = True
else:
if self.company_id.sale_create_invoice_policy == "stock_picking":
# A criação de Fatura de Serviços deve ser possível via Pedido
if not any(line.product_id.type == "service" for line in lines):
button_create_invoice_invisible = True
else:
# No caso da Politica de criação baseada no Pedido de Venda
# qdo acionado o Botão irá criar as Faturas automaticamente
# mesmo no caso de ter Produtos e Serviços
if not lines:
button_create_invoice_invisible = True

self.button_create_invoice_invisible = button_create_invoice_invisible

@api.onchange("partner_shipping_id")
def _onchange_partner_shipping_id(self):
"""
Expand Down
39 changes: 1 addition & 38 deletions l10n_br_sale_stock/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright (C) 2021 Magno Costa - Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, models
from odoo import models


class SaleOrderLine(models.Model):
Expand All @@ -19,40 +19,3 @@ def _prepare_procurement_values(self, group_id=False):
values["invoice_state"] = "2binvoiced"

return values

# no trigger product_id.invoice_policy to avoid retroactively changing SO
@api.depends("qty_invoiced", "qty_delivered", "product_uom_qty", "order_id.state")
def _get_to_invoice_qty(self):
"""
Compute the quantity to invoice. If the invoice policy is order,
the quantity to invoice is calculated from the ordered quantity.
Otherwise, the quantity delivered is used.
"""
result = super()._get_to_invoice_qty()

for line in self:
if line.order_id.state in ["sale", "done"]:
if line.product_id.invoice_policy == "order":
if (
line.order_id.company_id.sale_create_invoice_policy
== "stock_picking"
and line.product_id.type == "product"
):
# O correto seria que ao selecionar
# sale_create_invoice_policy 'stock_picking' os
# produtos tenham o campo invoice_policy definidos para
# 'delivery', porém para evitar que seja criada uma
# Fatura a partir do Pedido de Venda estamos
# alterando isso mesmo para os produtos definidos com
# 'order', já que a Politica de Criação da Fatura no
# caso do Tipo Produto está definida para ser a
# partir do stock.picking .
# TODO: Essa seria a melhor opção ? Por enquanto pelo
# que vi para ter o mesmo resultado, que é no caso
# sale_create_invoice_policy 'stock_picking' só ser
# possível criar a partir do sale.order Faturas das
# linhas que sejam type service sim, a outra opção
# seria sobre escrever o metodo action_invoice_create
# sem ser possível chamar o super.
line.qty_to_invoice = 0
return result
11 changes: 0 additions & 11 deletions l10n_br_sale_stock/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@
class StockMove(models.Model):
_inherit = "stock.move"

def _get_price_unit_invoice(self, inv_type, partner, qty=1):
result = super()._get_price_unit_invoice(inv_type, partner, qty)
# Caso tenha Sale Line já vem desagrupado aqui devido ao KEY
if len(self) == 1:
# Caso venha apenas uma linha porem sem
# sale_line_id é preciso ignora-la
if self.sale_line_id and self.sale_line_id.price_unit != result:
result = self.sale_line_id.price_unit

return result

def _get_new_picking_values(self):
# IMPORTANTE: a sequencia de update dos dicionarios quando o
# partner_shipping_id é diferente, o metodo do fiscal está
Expand Down
13 changes: 0 additions & 13 deletions l10n_br_sale_stock/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@
class StockPicking(models.Model):
_inherit = "stock.picking"

def _get_partner_to_invoice(self):
"""
If the partner has some invoicing contact defined
partner_invoice_id is auto filled, but it can also be changed.
partner_invoice_id is used if different from partner_id
"""
self.ensure_one()
partner_id = super()._get_partner_to_invoice()
if self.sale_id:
if partner_id != self.sale_id.partner_invoice_id.id:
partner_id = self.sale_id.partner_invoice_id.id
return partner_id

def _get_fiscal_partner(self):
self.ensure_one()
partner = super()._get_fiscal_partner()
Expand Down
10 changes: 10 additions & 0 deletions l10n_br_sale_stock/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
14.0.2.0.0 (2024-04-26)
~~~~~~~~~~~~~~~~~~~~~~~
* [REF] Extraction to module sale_stock_picking_invoicing
https://github.com/OCA/account-invoicing/pull/1025

14.0.1.0.0 (2022-09-16)
~~~~~~~~~~~~~~~~~~~~~~~

* [MIG] Migration to version 14.0

12.0.1.0.0 (2020-05-29)
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
49 changes: 32 additions & 17 deletions l10n_br_sale_stock/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,18 @@ <h1 class="title">Brazilian Localization Sales and Warehouse</h1>
<li><a class="reference internal" href="#installation" id="toc-entry-1">Installation</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-2">Configuration</a></li>
<li><a class="reference internal" href="#changelog" id="toc-entry-3">Changelog</a><ul>
<li><a class="reference internal" href="#section-1" id="toc-entry-4">12.0.1.0.0 (2020-05-29)</a></li>
<li><a class="reference internal" href="#section-2" id="toc-entry-5">10.0.1.0.0 (2019-09-13)</a></li>
<li><a class="reference internal" href="#section-1" id="toc-entry-4">14.0.2.0.0 (2024-04-26)</a></li>
<li><a class="reference internal" href="#section-2" id="toc-entry-5">14.0.1.0.0 (2022-09-16)</a></li>
<li><a class="reference internal" href="#section-3" id="toc-entry-6">12.0.1.0.0 (2020-05-29)</a></li>
<li><a class="reference internal" href="#section-4" id="toc-entry-7">10.0.1.0.0 (2019-09-13)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-6">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-7">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-8">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-9">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-10">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-11">Maintainers</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-8">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-9">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-10">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-11">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-12">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-13">Maintainers</a></li>
</ul>
</li>
</ul>
Expand All @@ -409,36 +411,49 @@ <h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
<div class="section" id="changelog">
<h1><a class="toc-backref" href="#toc-entry-3">Changelog</a></h1>
<div class="section" id="section-1">
<h2><a class="toc-backref" href="#toc-entry-4">12.0.1.0.0 (2020-05-29)</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">14.0.2.0.0 (2024-04-26)</a></h2>
<ul class="simple">
<li>[MIG] Migration to version 12.0</li>
<li>[REF] Extraction to module sale_stock_picking_invoicing
<a class="reference external" href="https://github.com/OCA/account-invoicing/pull/1025">https://github.com/OCA/account-invoicing/pull/1025</a></li>
</ul>
</div>
<div class="section" id="section-2">
<h2><a class="toc-backref" href="#toc-entry-5">10.0.1.0.0 (2019-09-13)</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">14.0.1.0.0 (2022-09-16)</a></h2>
<ul class="simple">
<li>[MIG] Migration to version 14.0</li>
</ul>
</div>
<div class="section" id="section-3">
<h2><a class="toc-backref" href="#toc-entry-6">12.0.1.0.0 (2020-05-29)</a></h2>
<ul class="simple">
<li>[MIG] Migration to version 12.0</li>
</ul>
</div>
<div class="section" id="section-4">
<h2><a class="toc-backref" href="#toc-entry-7">10.0.1.0.0 (2019-09-13)</a></h2>
<ul class="simple">
<li>[MIG] Migration to version 10.0</li>
</ul>
</div>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-8">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/l10n-brazil/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/l10n-brazil/issues/new?body=module:%20l10n_br_sale_stock%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-7">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-9">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-8">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-10">Authors</a></h2>
<ul class="simple">
<li>Akretion</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-9">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-11">Contributors</a></h2>
<ul class="simple">
<li>Renato Lima &lt;<a class="reference external" href="mailto:renato.lima&#64;akretion.com.br">renato.lima&#64;akretion.com.br</a>&gt;</li>
<li>Raphaël Valyi &lt;<a class="reference external" href="mailto:rvalyi&#64;akretion.com">rvalyi&#64;akretion.com</a>&gt;</li>
Expand All @@ -447,14 +462,14 @@ <h2><a class="toc-backref" href="#toc-entry-9">Contributors</a></h2>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-10">Other credits</a></h2>
<h2><a class="toc-backref" href="#toc-entry-12">Other credits</a></h2>
<p>The development of this module has been financially supported by:</p>
<ul class="simple">
<li>Aketion LTDA</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-13">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand Down
Loading
Loading