mirror of
https://bitbucket.org/presik/trytonpsk-sale_pos.git
synced 2023-12-14 07:13:02 +01:00
Fix invoice type
This commit is contained in:
parent
d5ff02c690
commit
47d1bdde46
2 changed files with 53 additions and 30 deletions
81
sale.py
81
sale.py
|
@ -1,11 +1,10 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import time
|
||||
# import time
|
||||
import math
|
||||
from decimal import Decimal
|
||||
from datetime import datetime, date
|
||||
from itertools import chain
|
||||
from simpleeval import simple_eval
|
||||
import math
|
||||
|
||||
from sql import Table
|
||||
from trytond.model import ModelView, fields
|
||||
|
@ -178,6 +177,35 @@ class Sale(metaclass=PoolMeta):
|
|||
amounts.append(val)
|
||||
return res + sum(amounts)
|
||||
|
||||
def create_invoice(self):
|
||||
'Create and return an invoice'
|
||||
pool = Pool()
|
||||
Invoice = pool.get('account.invoice')
|
||||
if self.invoice_method == 'manual':
|
||||
return
|
||||
|
||||
invoice_lines = []
|
||||
sales = [self]
|
||||
for sale in sales:
|
||||
for line in sale.lines:
|
||||
if self.total_amount < 0 and line.quantity > 0:
|
||||
continue
|
||||
if self.total_amount > 0 and line.quantity < 0:
|
||||
continue
|
||||
invoice_lines.append(line.get_invoice_line())
|
||||
invoice_lines = list(chain(*invoice_lines))
|
||||
if not invoice_lines:
|
||||
return
|
||||
|
||||
invoice = self._get_invoice_sale()
|
||||
if getattr(invoice, 'lines', None):
|
||||
invoice_lines = list(invoice.lines) + invoice_lines
|
||||
invoice.lines = invoice_lines
|
||||
invoice.save()
|
||||
|
||||
Invoice.update_taxes([invoice])
|
||||
return invoice
|
||||
|
||||
@classmethod
|
||||
def process_pos(cls, sale):
|
||||
pool = Pool()
|
||||
|
@ -207,7 +235,6 @@ class Sale(metaclass=PoolMeta):
|
|||
number = sale.invoice_number
|
||||
|
||||
position = sale.position if sale.position else None
|
||||
sale.state = 'processing'
|
||||
if invoice:
|
||||
if sale.invoice_date:
|
||||
inv_date = sale.invoice_date
|
||||
|
@ -215,18 +242,15 @@ class Sale(metaclass=PoolMeta):
|
|||
inv_date = Date.today()
|
||||
|
||||
sale.invoice = invoice.id
|
||||
sale.save()
|
||||
invoice.write([invoice], {
|
||||
to_write = {
|
||||
'shop': sale.shop.id,
|
||||
'invoice_date': inv_date,
|
||||
'number': number,
|
||||
'reference': sale.reference or sale.number,
|
||||
'position': position,
|
||||
})
|
||||
}
|
||||
|
||||
if sale.invoice_type:
|
||||
invoice.write([invoice], {
|
||||
'invoice_type': sale.invoice_type,
|
||||
})
|
||||
authorization_id = None
|
||||
if sale.untaxed_amount_cache > 0:
|
||||
if sale.invoice_type == 'P' and sale.shop.pos_authorization:
|
||||
|
@ -240,10 +264,10 @@ class Sale(metaclass=PoolMeta):
|
|||
else:
|
||||
if sale.shop.credit_note_electronic_authorization and sale.invoice_type in ['91', 'N']:
|
||||
authorization_id = sale.shop.credit_note_electronic_authorization.id
|
||||
if authorization_id:
|
||||
invoice.write([invoice], {
|
||||
'authorization': authorization_id,
|
||||
})
|
||||
|
||||
to_write['invoice_type'] = sale.invoice_type
|
||||
to_write['authorization'] = authorization_id
|
||||
invoice.write([invoice], to_write)
|
||||
|
||||
sale.save()
|
||||
return sale
|
||||
|
@ -381,15 +405,16 @@ class Sale(metaclass=PoolMeta):
|
|||
for sale in sales:
|
||||
if not sale.is_done():
|
||||
continue
|
||||
cls.do([sale])
|
||||
if sale.invoices:
|
||||
invoice = sale.invoices[0]
|
||||
if not sale.invoice:
|
||||
cls.write([sale], {
|
||||
'invoice': invoice.id,
|
||||
'invoice_number': invoice.number,
|
||||
'invoice_date': invoice.invoice_date,
|
||||
})
|
||||
# ?????
|
||||
# cls.do([sale])
|
||||
# if sale.invoices:
|
||||
# invoice = sale.invoices[0]
|
||||
# if not sale.invoice:
|
||||
# cls.write([sale], {
|
||||
# 'invoice': invoice.id,
|
||||
# 'invoice_numberx': invoice.number,
|
||||
# 'invoice_date': invoice.invoice_date,
|
||||
# })
|
||||
|
||||
@classmethod
|
||||
def do_stock_moves(cls, sales):
|
||||
|
@ -420,12 +445,12 @@ class Sale(metaclass=PoolMeta):
|
|||
invoice.invoice_date = _invoice_date
|
||||
if not getattr(invoice, 'accounting_date', False):
|
||||
invoice.accounting_date = _invoice_date or date.today()
|
||||
if invoice.invoice_type not in ('C', 'P', 'M'):
|
||||
if invoice.invoice_type not in ('P', 'M'):
|
||||
Invoice.validate_invoice([invoice])
|
||||
if hasattr(Invoice, 'submit'):
|
||||
Invoice.submit([invoice])
|
||||
|
||||
if invoice.invoice_type in ('C', 'P', 'M') or (
|
||||
if invoice.invoice_type in ('P', 'M') or (
|
||||
hasattr(invoice, 'cufe') and invoice.cufe):
|
||||
if sale.shop.workflow_invoice == 'validated':
|
||||
Invoice.write([invoice], {'state': 'validated'})
|
||||
|
@ -454,7 +479,6 @@ class Sale(metaclass=PoolMeta):
|
|||
continue
|
||||
try:
|
||||
for invoice in sale.invoices:
|
||||
|
||||
if invoice.state == 'paid' or not invoice.move:
|
||||
continue
|
||||
invoice_id = invoice.id
|
||||
|
@ -483,9 +507,7 @@ class Sale(metaclass=PoolMeta):
|
|||
'lines': [('add', reconcile_lines)],
|
||||
'date': TODAY,
|
||||
}])
|
||||
if sale.invoice or sale.invoices:
|
||||
sale.state = 'done'
|
||||
sale.save()
|
||||
sale.write([sale], {'state': 'done'})
|
||||
except Exception:
|
||||
print('Warning: Sale number not processed %s' % sale.number)
|
||||
|
||||
|
@ -495,6 +517,7 @@ class Sale(metaclass=PoolMeta):
|
|||
cls.post_invoices(_sales)
|
||||
cls.do_stock_moves([_sales])
|
||||
cls.do_reconcile([_sales])
|
||||
|
||||
cls.update_state([_sales])
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[tryton]
|
||||
version=5.0.3
|
||||
version=5.0.4
|
||||
depends:
|
||||
account
|
||||
account_statement
|
||||
|
|
Loading…
Reference in a new issue