Skip to content

Commit

Permalink
[MIG] l10n_br_sale_stock: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniospneto committed Sep 18, 2024
1 parent 876af38 commit 12a8399
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion l10n_br_sale_stock/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "AGPL-3",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-brazil",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"development_status": "Beta",
"maintainers": ["renatonlima", "mbcosta"],
"depends": [
Expand Down
3 changes: 0 additions & 3 deletions l10n_br_sale_stock/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Copyright (C) 2015 Renato Lima - Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import sale_order_line
from . import stock_move
from . import sale_order
Expand Down
8 changes: 4 additions & 4 deletions l10n_br_sale_stock/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def _prepare_procurement_values(self, group_id=False):
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):
@api.depends("qty_invoiced", "qty_delivered", "product_uom_qty", "state")
def _compute_qty_to_invoice(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()
result = super()._compute_qty_to_invoice()

for line in self:
if line.order_id.state in ["sale", "done"]:
if line.product_id.invoice_policy == "order":
if line.state in ["sale", "done"] and not line.display_type:
if (
line.order_id.company_id.sale_create_invoice_policy
== "stock_picking"
Expand Down
4 changes: 2 additions & 2 deletions l10n_br_sale_stock/tests/test_sale_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_02_sale_stock_return(self):
stock_picking = self.so.picking_ids

# compare sale.order.line with stock.move
stock_move = stock_picking.move_lines
stock_move = stock_picking.move_ids
sale_order_line = self.so.order_line

sm_fields = [key for key in self.env["stock.move"]._fields.keys()]
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_picking_sale_order_product_and_service(self):
self.assertTrue(
picking_devolution.fiscal_operation_id, "Missing Fiscal Operation."
)
for line in picking_devolution.move_lines:
for line in picking_devolution.move_ids:
self.assertEqual(line.invoice_state, "2binvoiced")
# Valida presença dos campos principais para o mapeamento Fiscal
self.assertTrue(line.fiscal_operation_id, "Missing Fiscal Operation.")
Expand Down
36 changes: 21 additions & 15 deletions l10n_br_sale_stock/wizards/stock_invoice_onshipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ def _build_invoice_values_from_pickings(self, pickings):
# Evita enviar False quando não tem nada
additional_data = ""
if pick.sale_id.manual_customer_additional_data:
additional_data = "{}".format(
pick.sale_id.manual_customer_additional_data
)
additional_data = f"{pick.sale_id.manual_customer_additional_data}"

values.update(
{
"manual_customer_additional_data": additional_data
+ " TERMOS E CONDIÇÕES: {}".format(pick.sale_id.note),
+ f" TERMOS E CONDIÇÕES: {pick.sale_id.note}",
}
)

Expand Down Expand Up @@ -87,16 +85,24 @@ def _get_invoice_line_values(self, moves, invoice_values, invoice):
values = super()._get_invoice_line_values(moves, invoice_values, invoice)
# Devido ao KEY com sale_line_id aqui
# vem somente um registro
if len(moves) == 1:
# Caso venha apenas uma linha porem sem
# sale_line_id é preciso ignora-la
if moves.sale_line_id:
values["sale_line_ids"] = [(6, 0, moves.sale_line_id.ids)]
values[
"analytic_account_id"
] = moves.sale_line_id.order_id.analytic_account_id.id
values["analytic_tag_ids"] = [
(6, 0, moves.sale_line_id.analytic_tag_ids.ids)
]
# Caso venha apenas uma linha porem sem
# sale_line_id é preciso ignora-la
if len(moves) != 1 or not moves.sale_line_id:
return values

sale_line_id = moves.sale_line_id
values["sale_line_ids"] = [(6, 0, sale_line_id.ids)]
sale_line_id = moves.sale_line_id
analytic_account_id = sale_line_id.order_id.analytic_account_id.id
if sale_line_id.analytic_distribution and not sale_line_id.display_type:
values["analytic_distribution"] = sale_line_id.analytic_distribution
if analytic_account_id and not sale_line_id.display_type:
analytic_account_id = str(analytic_account_id)
if "analytic_distribution" in values:
values["analytic_distribution"][analytic_account_id] = (
values["analytic_distribution"].get(analytic_account_id, 0) + 100
)
else:
values["analytic_distribution"] = {analytic_account_id: 100}

return values

0 comments on commit 12a8399

Please sign in to comment.