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][IMP] custom_p: Add changes in confirm multicompany. #3092

Merged
merged 2 commits into from
Jan 28, 2025
Merged
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
2 changes: 2 additions & 0 deletions custom_p/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"sale_order_usability",
"sale_order_line_gross_weight",
"custom_breeding_apps",
"custom_descarga",
"sale_order_confirm_multicompany",
],
"data": [
"security/ir.model.access.csv",
Expand Down
27 changes: 27 additions & 0 deletions custom_p/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@ class SaleOrder(models.Model):
copy=False,
)

def button_confirm_pickings(self):
if self.auto_purchase_order_id:
for line in self.order_line:
if line.auto_purchase_line_id:
lot = self.env["stock.production.lot"]
if line.lot_id:
lot_name = line.lot_id.name
company = line.sudo().auto_purchase_line_id.company_id
product = line.product_id
lot_domain = [
("name", "=", lot_name),
("company_id", "=", company.id),
("product_id", "=", product.id),
]
lot = lot.sudo().search(lot_domain)
if not lot:
lot = lot.sudo().action_create_lot(
product, lot_name, company
)
line.auto_purchase_line_id.sudo().write(
{
"lot_id": lot.id or False,
"return_qty": line.return_qty,
}
)
return super().button_confirm_pickings()

def button_return_picking(self):
self.update_line_qty = True
return super().button_return_picking()
Expand Down
17 changes: 16 additions & 1 deletion custom_p/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2024 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from datetime import timedelta

from odoo import api, fields, models

Expand Down Expand Up @@ -93,7 +94,21 @@ def _get_invoice_qty(self):

@api.model
def create(self, values):
if "customer_lead" not in values:
order = self.env["sale.order"].browse(values.get("order_id"))
product = self.env["product.product"].browse(values.get("product_id"))
values.update(
{"customer_lead": order._get_customer_lead(product.product_tmpl_id)}
)
result = super(SaleOrderLine, self).create(values)
if not result.order_id.commitment_date:
result.order_id.commitment_date = result.order_id.expected_date
order_date = fields.Datetime.from_string(
result.order_id.date_order
if result.order_id.date_order
and result.order_id.state in ["sale", "done"]
else fields.Datetime.now()
)
result.order_id.commitment_date = order_date + timedelta(
days=result.customer_lead or 0.0
)
return result
Loading