Skip to content

Commit

Permalink
Merge PR #3144 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 Jun 29, 2024
2 parents c50c323 + c6f09e0 commit 8055ed0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
15 changes: 8 additions & 7 deletions l10n_br_stock_account/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,16 @@ def _get_price_unit(self):
def _onchange_product_id_fiscal(self):
# Metodo super altera o price_unit
# TODO: Isso deveria ser resolvido no metodo principal?
price_unit = self.price_unit
result = super()._onchange_product_id_fiscal()
# Valor informado pelo usuario tem prioridade
if self.product_id and price_unit == 0.0:
price_unit = self._get_price_unit()
if self.picking_id.fiscal_operation_id:
price_unit = self.price_unit
result = super()._onchange_product_id_fiscal()
# Valor informado pelo usuario tem prioridade
if self.product_id and price_unit == 0.0:
price_unit = self._get_price_unit()

self.price_unit = price_unit
self.price_unit = price_unit

return result
return result

def _split(self, qty, restrict_partner_id=False):
new_moves_vals = super()._split(qty, restrict_partner_id)
Expand Down
38 changes: 29 additions & 9 deletions l10n_br_stock_account/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,35 @@ class StockPicking(models.Model):
@api.model
def _default_fiscal_operation(self):
company = self.env.company
fiscal_operation = company.stock_fiscal_operation_id
picking_type_id = self.env.context.get("default_picking_type_id")
if picking_type_id:
picking_type = self.env["stock.picking.type"].browse(picking_type_id)
fiscal_operation = picking_type.fiscal_operation_id or (
company.stock_in_fiscal_operation_id
if picking_type.code == "incoming"
else company.stock_out_fiscal_operation_id
)
fiscal_operation = False
if self.env.company.country_id == self.env.ref("base.br"):
fiscal_operation = company.stock_fiscal_operation_id
picking_type_id = self.env.context.get("default_picking_type_id")
if picking_type_id:
picking_type = self.env["stock.picking.type"].browse(picking_type_id)
fiscal_operation = picking_type.fiscal_operation_id or (
company.stock_in_fiscal_operation_id
if picking_type.code == "incoming"
else company.stock_out_fiscal_operation_id
)

# Casos onde o usuário definiu o Pedido de Compra/Venda como
# 'Sem Operação Fiscal'
if hasattr(self, "purchase_id"):
if not self.purchase_id.fiscal_operation_id:
fiscal_operation = False
if hasattr(self, "sale_id"):
# Necessário para evitar o erro quando o l10n_br_purchase_stock
# é instalado:
# /l10n_br_stock_account/models/stock_picking.py", line 34,
# in _default_fiscal_operation
# if not self.sale_id.fiscal_operation_id:
# AttributeError: 'sale.order' object has no attribute
# 'fiscal_operation_id'
if hasattr(self.sale_id, "fiscal_operation_id"):
if not self.sale_id.fiscal_operation_id:
fiscal_operation = False

return fiscal_operation

@api.model
Expand Down
2 changes: 0 additions & 2 deletions l10n_br_stock_account/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def _run_fiscal_line_onchanges(self, record):

# 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()

Expand Down

0 comments on commit 8055ed0

Please sign in to comment.