add advances in sales
This commit is contained in:
parent
53db407f06
commit
f6d1bd9987
39
sale.py
39
sale.py
|
@ -5,6 +5,7 @@ import calendar
|
|||
from decimal import Decimal
|
||||
from datetime import datetime, date, timedelta
|
||||
from itertools import chain
|
||||
from flask import Config
|
||||
|
||||
from sql import Null, Table, With
|
||||
from sql.operators import NotIn, Or
|
||||
|
@ -55,6 +56,7 @@ class Sale(metaclass=PoolMeta):
|
|||
pre_sale = fields.Boolean('Pre-Sale', help="This option for pre-sale, change method of invoice to shipment")
|
||||
shipment_date = fields.Date('Shipment Date', states=STATES)
|
||||
turn = fields.Integer('Turn', states=STATES)
|
||||
reservation= fields.Boolean('Reservation')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -508,48 +510,69 @@ class Sale(metaclass=PoolMeta):
|
|||
Invoice.validate_invoice([invoice])
|
||||
return
|
||||
Invoice.process_invoice([invoice])
|
||||
if invoice.state == 'posted' and sale.residual_amount <= 0:
|
||||
try:
|
||||
cls.do_reconcile([sale])
|
||||
except:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def do_reconcile(cls, sales):
|
||||
print('ingresa to reconcile')
|
||||
Reconciliation = Pool().get('account.move.reconciliation')
|
||||
Config = Pool().get('sale.configuration')
|
||||
account_advance = Config(1).advance_account.id if Config(1).advance_account else None
|
||||
for sale in sales:
|
||||
reconcile_lines = []
|
||||
advance_lines = []
|
||||
account_reconcile_id = None
|
||||
invoice_id = None
|
||||
if not sale.payments or not sale.number:
|
||||
continue
|
||||
try:
|
||||
# if 1:
|
||||
for invoice in sale.invoices:
|
||||
print('ingresa a invoice')
|
||||
if invoice.state == 'paid' or not invoice.move:
|
||||
print('no hace nada---')
|
||||
continue
|
||||
invoice_id = invoice.id
|
||||
invoice_ = invoice
|
||||
|
||||
account_reconcile_id = invoice.account.id
|
||||
for line in invoice.payment_lines:
|
||||
if not line.reconciliation and line.account.id == account_reconcile_id:
|
||||
reconcile_lines.append(line.id)
|
||||
reconcile_lines.append(line)
|
||||
for l in invoice.move.lines:
|
||||
if l.account.id == account_reconcile_id:
|
||||
reconcile_lines.append(l.id)
|
||||
reconcile_lines.append(l)
|
||||
break
|
||||
|
||||
for st_line in sale.payments:
|
||||
st_line.invoice = invoice_id
|
||||
st_line.save()
|
||||
if st_line.account.id == invoice_.account.id:
|
||||
st_line.invoice = invoice_id
|
||||
st_line.save()
|
||||
elif st_line.move and st_line.move.state != 'posted':
|
||||
st_line.move.post([st_line.move])
|
||||
if not st_line.move:
|
||||
st_line.create_move()
|
||||
|
||||
|
||||
for ml in st_line.move.lines:
|
||||
if not ml.reconciliation and ml.account.id == account_reconcile_id:
|
||||
reconcile_lines.append(ml.id)
|
||||
|
||||
if reconcile_lines:
|
||||
reconcile_lines.append(ml)
|
||||
if account_advance and not ml.reconciliation and ml.account.id == account_advance:
|
||||
advance_lines.append(ml)
|
||||
if advance_lines:
|
||||
invoice_.create_cross_advance(advance_lines)
|
||||
amount_reconcile = sum(l.debit-l.credit for l in reconcile_lines)
|
||||
if reconcile_lines and amount_reconcile == 0:
|
||||
Reconciliation.create([{
|
||||
'lines': [('add', reconcile_lines)],
|
||||
'date': TODAY,
|
||||
}])
|
||||
sale.write([sale], {'state': 'done'})
|
||||
except Exception:
|
||||
# else:
|
||||
print('Warning: Sale number not processed %s' % sale.number)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -51,11 +51,13 @@ copyright notices and license terms. -->
|
|||
</xpath>
|
||||
<xpath expr="/form/notebook/page/field[@name='shipment_method']"
|
||||
position="after">
|
||||
<label name="shipment_date"/>
|
||||
<field name="shipment_date"/>
|
||||
<label name="self_pick_up"/>
|
||||
<field name="self_pick_up"/>
|
||||
<label name="pre_sale"/>
|
||||
<field name="pre_sale"/>
|
||||
<label name="shipment_date"/>
|
||||
<field name="shipment_date"/>
|
||||
<label name="self_pick_up"/>
|
||||
<field name="self_pick_up"/>
|
||||
<label name="pre_sale"/>
|
||||
<field name="pre_sale"/>
|
||||
<label name="reservation"/>
|
||||
<field name="reservation"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue