summaryrefslogtreecommitdiff
path: root/fixco_custom/models
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-01-08 09:52:38 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-01-08 09:52:38 +0700
commit9990c0c6e30260f1c9ae2111893495ce7bd1c03c (patch)
tree81847c26ea054636d6178884ba3dd812e477d494 /fixco_custom/models
parent71736a301eca62a55c34c96b3a9d0c06ee28f3d9 (diff)
parent23b2c540774c064a69c77ed3de29d9f99ffae904 (diff)
Merge branch 'main' of https://bitbucket.org/altafixco/fixco-addons into print_picking_list
merge
Diffstat (limited to 'fixco_custom/models')
-rwxr-xr-xfixco_custom/models/__init__.py1
-rwxr-xr-xfixco_custom/models/detail_order.py2
-rw-r--r--fixco_custom/models/purchase_order.py47
-rw-r--r--fixco_custom/models/purchase_order_multi_bills.py62
-rwxr-xr-xfixco_custom/models/sale.py1
-rw-r--r--fixco_custom/models/shipment_group.py2
-rw-r--r--fixco_custom/models/upload_cancel_picking.py6
-rw-r--r--fixco_custom/models/upload_ginee.py1
8 files changed, 119 insertions, 3 deletions
diff --git a/fixco_custom/models/__init__.py b/fixco_custom/models/__init__.py
index c13c9a3..0068d32 100755
--- a/fixco_custom/models/__init__.py
+++ b/fixco_custom/models/__init__.py
@@ -38,3 +38,4 @@ from . import account_move_reversal
from . import upload_cancel_picking
from . import product_supplierinfo
from . import queue_job
+from . import purchase_order_multi_bills \ No newline at end of file
diff --git a/fixco_custom/models/detail_order.py b/fixco_custom/models/detail_order.py
index 847c41e..b3e10a2 100755
--- a/fixco_custom/models/detail_order.py
+++ b/fixco_custom/models/detail_order.py
@@ -370,7 +370,7 @@ class DetailOrder(models.Model):
sale_order.note_by_buyer = json_data.get('data', [{}])[0].get('extraInfo', []).get('noteByBuyer', [])
sale_order.action_cancel()
- self.execute_status = 'cancelled_so_created'
+ self.execute_status = 'cancelled_so'
return
diff --git a/fixco_custom/models/purchase_order.py b/fixco_custom/models/purchase_order.py
index 43fe8f6..ef80112 100644
--- a/fixco_custom/models/purchase_order.py
+++ b/fixco_custom/models/purchase_order.py
@@ -58,6 +58,53 @@ class PurchaseOrder(models.Model):
soo_tax = fields.Float('SOO Tax', copy=False)
discount_total = fields.Float('Discount Total', help = 'Total Discount for Each Product', copy=False, default=0.0)
+ def _prepare_invoice(self):
+ """Prepare the dict of values to create the new invoice for a purchase order.
+ """
+ self.ensure_one()
+ move_type = self._context.get('default_move_type', 'in_invoice')
+ journal = self.env['account.move'].with_context(default_move_type=move_type)._get_default_journal()
+ if not journal:
+ raise UserError(_('Please define an accounting purchase journal for the company %s (%s).') % (self.company_id.name, self.company_id.id))
+
+ partner_invoice_id = self.partner_id.address_get(['invoice'])['invoice']
+ partner_bank_id = self.partner_id.commercial_partner_id.bank_ids.filtered_domain(['|', ('company_id', '=', False), ('company_id', '=', self.company_id.id)])[:1]
+ invoice_vals = {
+ 'ref': self.partner_ref or '',
+ 'move_type': move_type,
+ 'invoice_date': datetime.utcnow(),
+ 'narration': self.notes,
+ 'currency_id': self.currency_id.id,
+ 'invoice_user_id': self.user_id and self.user_id.id or self.env.user.id,
+ 'partner_id': partner_invoice_id,
+ 'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id.get_fiscal_position(partner_invoice_id)).id,
+ 'payment_reference': self.partner_ref or '',
+ 'partner_bank_id': partner_bank_id.id,
+ 'invoice_origin': self.name,
+ 'invoice_payment_term_id': self.payment_term_id.id,
+ 'invoice_line_ids': [],
+ 'company_id': self.company_id.id,
+ }
+ return invoice_vals
+
+ @api.constrains('invoice_ids')
+ def _auto_action_post_bills(self):
+ for bill in self.invoice_ids:
+ if bill.state == 'draft':
+ bill.action_post()
+
+ def open_form_multi_create_bills(self):
+ return {
+ 'name': _('Create Bills'),
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'purchase.order.multi_bills',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': {
+ 'po_ids': self.ids,
+ }
+ }
+
def _get_fixco_token(self, source='auto'):
ICP = self.env['ir.config_parameter'].sudo()
TokenLog = self.env['token.log'].sudo()
diff --git a/fixco_custom/models/purchase_order_multi_bills.py b/fixco_custom/models/purchase_order_multi_bills.py
new file mode 100644
index 0000000..d9e3c0d
--- /dev/null
+++ b/fixco_custom/models/purchase_order_multi_bills.py
@@ -0,0 +1,62 @@
+from odoo import models, fields, api, _
+from odoo.exceptions import UserError
+
+class PurchaeOrderMultiBills(models.TransientModel):
+ _name = 'purchase.order.multi_bills'
+ _description = 'Create bills for Multiple purchases Orders'
+
+ def queue_job(self):
+ po_ids = self._context.get('po_ids', [])
+ purchase_orders = self.env['purchase.order'].browse(po_ids)
+ for purchase in purchase_orders:
+ queue_job = self.env['queue.job'].search([('res_id', '=', purchase.id), ('method_name', '=', 'create_bills')], limit=1)
+ if queue_job:
+ continue
+ self.env['queue.job'].create({
+ 'name': f'Create Bills {purchase.name}',
+ 'model_name': 'purchase.order',
+ 'method_name': 'action_create_invoice',
+ 'res_id': purchase.id,
+ })
+
+ # def create_bills(self):
+ # # Get SO IDs from context
+ # po_ids = self._context.get('po_ids', [])
+ # if not po_ids:
+ # raise UserError(_("No purchases orders selected!"))
+
+ # # Browse all selected purchases orders
+ # purchase_orders = self.env['purchase.order'].browse(po_ids)
+ # created_bills = self.env['account.move']
+
+ # # Create one invoice per SO (even if partner is the same)
+ # for order in purchase_orders:
+ # # Create invoice for this SO only
+ # invoice = order.with_context(default_invoice_origin=order.name)._create_bills(final=True)
+ # invoice.action_post()
+ # created_bills += invoice
+
+ # # Link the invoice to the SO
+ # order.invoice_ids += invoice
+
+ # # Return action to view created bills
+ # if len(created_bills) > 1:
+ # action = {
+ # 'name': _('Created bills'),
+ # 'type': 'ir.actions.act_window',
+ # 'res_model': 'account.move',
+ # 'view_mode': 'tree,form',
+ # 'domain': [('id', 'in', created_bills.ids)],
+ # }
+ # elif created_bills:
+ # action = {
+ # 'name': _('Created Invoice'),
+ # 'type': 'ir.actions.act_window',
+ # 'res_model': 'account.move',
+ # 'view_mode': 'form',
+ # 'res_id': created_bills.id,
+ # }
+ # else:
+ # action = {'type': 'ir.actions.act_window_close'}
+
+ # return action \ No newline at end of file
diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py
index 8b04538..cd5f68f 100755
--- a/fixco_custom/models/sale.py
+++ b/fixco_custom/models/sale.py
@@ -25,6 +25,7 @@ class SaleOrder(models.Model):
# Create invoice for this SO only
invoice = order.with_context(default_invoice_origin=order.name)._create_invoices(final=True)
invoice.action_post()
+ invoice.invoice_date = invoice.picking_id.date_done
created_invoices += invoice
# Link the invoice to the SO
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py
index 2e2dffa..4c4af4a 100644
--- a/fixco_custom/models/shipment_group.py
+++ b/fixco_custom/models/shipment_group.py
@@ -215,7 +215,7 @@ class ShipmentGroup(models.Model):
return
for item in contents:
- order_no = item.get('orderNumber')
+ order_no = item.get('externalOrderId')
order_status = item.get('orderStatus')
picking_line = order_map.get(order_no)
diff --git a/fixco_custom/models/upload_cancel_picking.py b/fixco_custom/models/upload_cancel_picking.py
index b4038bf..54a94d5 100644
--- a/fixco_custom/models/upload_cancel_picking.py
+++ b/fixco_custom/models/upload_cancel_picking.py
@@ -144,9 +144,13 @@ class UploadCancelPicking(models.Model):
}
def action_cancel_picking(self):
+ self.date_upload = datetime.utcnow()
for line in self.picking_lines:
+ queue_job = self.env['queue.job'].search([('res_id', '=', line.id), ('method_name', '=', 'cancel_picking')], limit=1)
+ if queue_job:
+ continue
self.env['queue.job'].create({
- 'name': f'Cancel Picking {line.name}',
+ 'name': f'Cancel Picking {line.picking_id.name}',
'model_name': 'upload.cancel.picking.line',
'method_name': 'cancel_picking',
'res_id': line.id,
diff --git a/fixco_custom/models/upload_ginee.py b/fixco_custom/models/upload_ginee.py
index 4341269..282bf74 100644
--- a/fixco_custom/models/upload_ginee.py
+++ b/fixco_custom/models/upload_ginee.py
@@ -167,6 +167,7 @@ class UploadGinee(models.Model):
# self.ginee_lines.create_so_and_detail_order()
def action_get_order_id_and_create_detail_order(self):
+ self.date_upload = datetime.utcnow()
for line in self.ginee_lines:
queue_job = self.env['queue.job'].search([('res_id', '=', line.id), ('method_name', '=', 'get_order_id_and_create_detail_order')], limit=1)
if queue_job: