diff options
| -rw-r--r-- | indoteknik_custom/models/stock_move.py | 33 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 12 |
2 files changed, 40 insertions, 5 deletions
diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index 22a73010..bdbb0227 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -6,6 +6,39 @@ class StockMove(models.Model): line_no = fields.Integer('No', default=0) + def _prepare_account_move_line_from_mr(self, po_line, qty, move=False): + po_line.ensure_one() + aml_currency = move and move.currency_id or po_line.currency_id + date = move and move.date or fields.Date.today() + res = { + 'display_type': po_line.display_type, + 'sequence': po_line.sequence, + 'name': '%s: %s' % (po_line.order_id.name, po_line.name), + 'product_id': po_line.product_id.id, + 'product_uom_id': po_line.product_uom.id, + 'quantity': qty, + 'price_unit': po_line.currency_id._convert(po_line.price_unit, aml_currency, po_line.company_id, date, round=False), + 'tax_ids': [(6, 0, po_line.taxes_id.ids)], + 'analytic_account_id': po_line.account_analytic_id.id, + 'analytic_tag_ids': [(6, 0, po_line.analytic_tag_ids.ids)], + 'purchase_line_id': po_line.id, + } + if not move: + return res + + if self.currency_id == move.company_id.currency_id: + currency = False + else: + currency = move.currency_id + + res.update({ + 'move_id': move.id, + 'currency_id': currency and currency.id or False, + 'date_maturity': move.invoice_date_due, + 'partner_id': move.partner_id.id, + }) + return res + def _create_account_move_line(self, credit_account_id, debit_account_id, journal_id, qty, description, svl_id, cost): self.ensure_one() if self.picking_id.is_internal_use: diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 77af676c..e63370f5 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -84,15 +84,17 @@ class StockPicking(models.Model): # Invoice values. invoice_vals = order._prepare_invoice() # Invoice line values (keep only necessary sections). - for line in order.order_line: - if line.display_type == 'line_section': + for line in self.move_ids_without_package: + po_line = self.env['purchase.order.line'].search([('order_id', '=', po.id), ('product_id', '=', line.product_id.id)], limit=1) + qty = line.product_uom_qty + if po_line.display_type == 'line_section': pending_section = line continue - if not float_is_zero(line.qty_to_invoice, precision_digits=precision): + if not float_is_zero(po_line.qty_to_invoice, precision_digits=precision): if pending_section: - invoice_vals['invoice_line_ids'].append((0, 0, pending_section._prepare_account_move_line())) + invoice_vals['invoice_line_ids'].append((0, 0, pending_section._prepare_account_move_line_from_mr(po_line, qty))) pending_section = None - invoice_vals['invoice_line_ids'].append((0, 0, line._prepare_account_move_line())) + invoice_vals['invoice_line_ids'].append((0, 0, line._prepare_account_move_line_from_mr(po_line, qty))) invoice_vals_list.append(invoice_vals) if not invoice_vals_list: |
