Skip to content

Commit

Permalink
Merge PR OCA#2799 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by rvalyi
  • Loading branch information
OCA-git-bot committed Dec 1, 2023
2 parents 5c33fb3 + 77ca2c4 commit 8f9fcd5
Show file tree
Hide file tree
Showing 10 changed files with 724 additions and 398 deletions.
2 changes: 1 addition & 1 deletion l10n_br_purchase_stock/tests/test_stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_stock_rule_purchase(self):
orderpoint = self.env["stock.warehouse.orderpoint"].create(
{
"product_id": self.env.ref("product.product_product_12").id,
"product_min_qty": 100.0,
"product_min_qty": 1000.0,
}
)

Expand Down
1 change: 1 addition & 0 deletions l10n_br_stock_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"demo/company_demo.xml",
"demo/l10n_br_stock_account_demo.xml",
"demo/account_journal_demo.xml",
"demo/stock_inventory_demo.xml",
],
"installable": True,
"post_init_hook": "post_init_hook",
Expand Down
366 changes: 280 additions & 86 deletions l10n_br_stock_account/demo/l10n_br_stock_account_demo.xml

Large diffs are not rendered by default.

132 changes: 132 additions & 0 deletions l10n_br_stock_account/demo/stock_inventory_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<!-- Empresa Principal - Main Company -->
<record id="stock_account_inventory_main" model="stock.inventory">
<field
name="name"
>Inventário Inicial l10n_br_stock_account - Empresa Principal</field>
<field name="company_id" ref="base.main_company" />
</record>

<record id="stock_account_inventory_main_line_1" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_12" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="inventory_id" ref="stock_account_inventory_main" />
<field name="product_qty">100.0</field>
<field name="location_id" ref="stock.stock_location_stock" />
</record>

<record id="stock_account_inventory_main_line_2" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_16" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="inventory_id" ref="stock_account_inventory_main" />
<field name="product_qty">100.0</field>
<field name="location_id" ref="stock.stock_location_stock" />
</record>

<function model="stock.inventory" name="action_start">
<function
eval="[[('state','=','draft'),('id', '=', ref('stock_account_inventory_main'))]]"
model="stock.inventory"
name="search"
/>
</function>
<function model="stock.inventory" name="action_validate">
<function
eval="[[('state','=','confirm'),('id', '=', ref('stock_account_inventory_main'))]]"
model="stock.inventory"
name="search"
/>
</function>

<!-- Simples Nacional -->
<record id="stock_account_inventory_sn" model="stock.inventory">
<field
name="name"
>Inventário Inicial l10n_br_stock_account - Simples Nacional</field>
<field name="company_id" ref="l10n_br_base.empresa_simples_nacional" />
</record>

<record id="stock_account_inventory_sn_line_1" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_12" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="inventory_id" ref="stock_account_inventory_sn" />
<field name="product_qty">100.0</field>
<field
name="location_id"
ref="l10n_br_stock.wh_empresa_simples_nacional_loc_stock_id"
/>
</record>
<record id="stock_account_inventory_sn_line_2" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_16" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="inventory_id" ref="stock_account_inventory_sn" />
<field name="product_qty">100.0</field>
<field
name="location_id"
ref="l10n_br_stock.wh_empresa_simples_nacional_loc_stock_id"
/>
</record>

<function model="stock.inventory" name="action_start">
<function
eval="[[('state','=','draft'),('id', '=', ref('stock_account_inventory_sn'))]]"
model="stock.inventory"
name="search"
/>
</function>
<function model="stock.inventory" name="action_validate">
<function
eval="[[('state','=','confirm'),('id', '=', ref('stock_account_inventory_sn'))]]"
model="stock.inventory"
name="search"
/>
</function>

<!-- Lucro Presumido -->

<record id="stock_account_inventory_lp" model="stock.inventory">
<field
name="name"
>Inventário Inicial l10n_br_stock_account - Lucro Presumido</field>
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
</record>

<record id="stock_inventory_lp_line_1" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_12" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="inventory_id" ref="stock_account_inventory_lp" />
<field name="product_qty">100.0</field>
<field
name="location_id"
ref="l10n_br_stock.wh_empresa_lucro_presumido_loc_stock_id"
/>
</record>
<record id="stock_inventory_lp_line_2" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_16" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="inventory_id" ref="stock_account_inventory_lp" />
<field name="product_qty">100.0</field>
<field
name="location_id"
ref="l10n_br_stock.wh_empresa_lucro_presumido_loc_stock_id"
/>
</record>

<function model="stock.inventory" name="action_start">
<function
eval="[[('state','=','draft'),('id', '=', ref('stock_account_inventory_lp'))]]"
model="stock.inventory"
name="search"
/>
</function>
<function model="stock.inventory" name="action_validate">
<function
eval="[[('state','=','confirm'),('id', '=', ref('stock_account_inventory_lp'))]]"
model="stock.inventory"
name="search"
/>
</function>

</odoo>
14 changes: 12 additions & 2 deletions l10n_br_stock_account/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,18 @@ def _prepare_merge_move_sort_method(self, move):
return keys_sorted

def _prepare_extra_move_vals(self, qty):
values = self._prepare_br_fiscal_dict()
values = {}
if self.fiscal_operation_id:
# Caso Brasil se caracteriza por ter Operação Fiscal
values = self._prepare_br_fiscal_dict()
values.update(super()._prepare_extra_move_vals(qty))
return values

def _prepare_move_split_vals(self, uom_qty):
values = self._prepare_br_fiscal_dict()
values = {}
if self.fiscal_operation_id:
# Caso Brasil se caracteriza por ter Operação Fiscal
values = self._prepare_br_fiscal_dict()
values.update(super()._prepare_move_split_vals(uom_qty))
return values

Expand Down Expand Up @@ -163,6 +169,10 @@ def _onchange_product_id_fiscal(self):

def _split(self, qty, restrict_partner_id=False):
new_moves_vals = super()._split(qty, restrict_partner_id)
if not self.fiscal_operation_id:
# Caso Brasil se caracteriza por ter Operação Fiscal
return new_moves_vals

self._onchange_commercial_quantity()
self._onchange_fiscal_taxes()

Expand Down
1 change: 1 addition & 0 deletions l10n_br_stock_account/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import common
from . import test_invoicing_picking
from . import test_stock_rule
86 changes: 86 additions & 0 deletions l10n_br_stock_account/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright (C) 2023-Today - Akretion (<http://www.akretion.com>).
# @author Magno Costa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import Form, TransactionCase


class TestBrPickingInvoicingCommon(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

def _change_user_company(self, company):
self.env.user.company_ids += company
self.env.user.company_id = company

def _run_fiscal_onchanges(self, record):
record._onchange_fiscal_operation_id()

def _run_fiscal_line_onchanges(self, record):
# Mixin Fiscal
record._onchange_commercial_quantity()

# Stock Move
record._onchange_product_id_fiscal()
record._onchange_fiscal_operation_id()
record._onchange_fiscal_operation_line_id()
record._onchange_fiscal_taxes()
record._onchange_product_quantity()

def picking_move_state(self, picking):
self._run_fiscal_onchanges(picking)
picking.action_confirm()
# Check product availability
picking.action_assign()
# Force product availability
for move in picking.move_ids_without_package:
self._run_fiscal_line_onchanges(move)
move.quantity_done = move.product_uom_qty
picking.button_validate()

def create_invoice_wizard(self, pickings):
wizard_obj = self.env["stock.invoice.onshipping"].with_context(
active_ids=pickings.ids,
active_model=pickings._name,
)
fields_list = wizard_obj.fields_get().keys()
wizard_values = wizard_obj.default_get(fields_list)
# One invoice per partner but group products
wizard_values.update({"group": "partner_product"})
wizard = wizard_obj.create(wizard_values)
wizard.onchange_group()
wizard.action_generate()
domain = [("picking_ids", "in", pickings.ids)]
invoice = self.env["account.move"].search(domain)
return invoice

def return_picking_wizard(self, picking):
# Return Picking
return_wizard_form = Form(
self.env["stock.return.picking"].with_context(
**dict(active_id=picking.id, active_model="stock.picking")
)
)
return_wizard_form.invoice_state = "2binvoiced"
self.return_wizard = return_wizard_form.save()

result_wizard = self.return_wizard.create_returns()
self.assertTrue(result_wizard, "Create returns wizard fail.")
picking_devolution = self.env["stock.picking"].browse(
result_wizard.get("res_id")
)
return picking_devolution

def create_backorder_wizard(self, picking):
res_dict_for_back_order = picking.button_validate()
backorder_wizard = Form(
self.env[res_dict_for_back_order["res_model"]].with_context(
**res_dict_for_back_order["context"]
)
).save()
backorder_wizard.process()
backorder = self.env["stock.picking"].search(
[("backorder_id", "=", picking.id)]
)
return backorder
Loading

0 comments on commit 8f9fcd5

Please sign in to comment.