Skip to content

Commit

Permalink
Merge pull request #421 from frePPLe/17.0
Browse files Browse the repository at this point in the history
Syncing from upstream frePPLe/odoo (17.0)
  • Loading branch information
bt-admin authored Feb 22, 2024
2 parents 4ec9c2d + f8c4c9f commit f016035
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
42 changes: 30 additions & 12 deletions frepple/controllers/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def __init__(self, req, database=None, company=None, mode=1):
def run(self):
msg = []
if self.actual_user:
product_product = self.env["product.product"].with_user(self.actual_user)
product_supplierinfo = self.env["product.supplierinfo"].with_user(
self.actual_user
)
uom_uom = self.env["uom.uom"].with_user(self.actual_user)
proc_order = self.env["purchase.order"].with_user(self.actual_user)
proc_orderline = self.env["purchase.order.line"].with_user(self.actual_user)
mfg_order = self.env["mrp.production"].with_user(self.actual_user)
Expand All @@ -93,6 +98,9 @@ def run(self):
self.actual_user
)
else:
product_product = self.env["product.product"]
product_supplierinfo = self.env["product.supplierinfo"]
uom_uom = self.env["uom.uom"]
proc_order = self.env["purchase.order"]
proc_orderline = self.env["purchase.order.line"]
mfg_order = self.env["mrp.production"]
Expand Down Expand Up @@ -271,10 +279,8 @@ def run(self):
] = date_ordered

if (item_id, supplier_id) not in product_supplier_dict:
product = self.env["product.product"].browse(int(item_id))
product_supplierinfo = self.env[
"product.supplierinfo"
].search(
product = product_product.browse(int(item_id))
supplier = product_supplierinfo.search(
[
("partner_id", "=", supplier_id),
(
Expand All @@ -287,21 +293,30 @@ def run(self):
limit=1,
order="min_qty desc",
)
if product_supplierinfo:
price_unit = product_supplierinfo.price
else:
price_unit = 0
product_uom = uom_uom.browse(int(uom_id))
# first create a minimal PO line
po_line = proc_orderline.create(
{
"order_id": supplier_reference[supplier_id]["id"],
"product_id": int(item_id),
"product_qty": quantity,
"product_uom": int(uom_id),
"date_planned": date_planned,
"price_unit": price_unit,
"name": elem.get("item"),
}
)
# Then let odoo computes all the fields (taxes, name, description...)

d = po_line._prepare_purchase_order_line(
product,
quantity,
product_uom,
self.company,
supplier,
po,
)
d["date_planned"] = date_planned
# Finally update the PO line
po_line.write(d)

# Aggregation of quantities under the same PO line
# only happens in incremental export
if self.mode == 2:
Expand Down Expand Up @@ -588,7 +603,7 @@ def run(self):
if wo_data:
for wo in mo.workorder_ids:
for rec in wo_data:
if rec["id"] == wo.operation_id.id:
if rec["id"] == wo.id:
# By default odoo populates the scheduled start date field only when you confirm and plan
# the manufacturing order.
# Here we are already updating it earlier
Expand Down Expand Up @@ -621,6 +636,9 @@ def run(self):

countmfg += 1
except Exception as e:
import traceback

logger.info(traceback.format_exc())
logger.error("Exception %s" % e)
msg.append(str(e))
# Remove the element now to keep the DOM tree small
Expand Down
9 changes: 6 additions & 3 deletions frepple/controllers/outbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,10 @@ def export_items(self):
)
suppliers = {}
for sup in results:
name = self.map_customers.get(sup["partner_id"][0])
name = self.map_customers.get(sup["partner_id"][0], None)
if not name:
# Skip uninterested suppliers (eg archived ones)
continue
if sup.get("is_subcontractor", False):
if not hasattr(tmpl, "subcontractors"):
tmpl["subcontractors"] = []
Expand Down Expand Up @@ -2464,7 +2467,7 @@ def export_manufacturingorders(self):
)

yield '<suboperation><operation name=%s priority="%s" type="operation_fixed_time" duration="%s"><location name=%s/><flows>' % (
quoteattr(suboperation),
quoteattr("%s - %s" % (suboperation, wo["id"])),
idx,
self.convert_float_time(
max(time_left, 1), # Miniminum 1 minute remaining :-)
Expand Down Expand Up @@ -2626,7 +2629,7 @@ def export_manufacturingorders(self):
wo_date,
qty,
state,
quoteattr(suboperation),
quoteattr("%s - %s" % (suboperation, wo["id"])),
quoteattr(i["name"]),
)
if (
Expand Down

0 comments on commit f016035

Please sign in to comment.