add action generate shipment

This commit is contained in:
wilson gomez 2021-05-18 10:27:56 -05:00
parent 9807db81d6
commit 975bf0adfa
4 changed files with 92 additions and 10 deletions

View file

@ -63,4 +63,5 @@ def register():
sale.PortfolioPayments,
statement.OpenStatement,
statement.CloseStatement,
sale.SaleGenerateShipment,
module='sale_pos', type_='wizard')

View file

@ -10,6 +10,10 @@ msgctxt "error:account.statement:"
msgid "There is not count money!"
msgstr "No hay conteo de dinero!"
msgctxt "error:account.statement:"
msgid "This statement %s cannot be deleted because it has payments"
msgstr ""
msgctxt "error:close.statement:"
msgid "Statement %s already closed. \n"
msgstr "Estado de Cuenta %s Cerrado."
@ -56,6 +60,10 @@ msgctxt "error:sale.payment:"
msgid "You have not defined a sale device for your user."
msgstr "No ha definido un terminal de venta para su usuario."
msgctxt "error:sale.sale.generate_shipment:"
msgid "You can not to generate shipment!"
msgstr "No puede generar el envío"
msgctxt "error:sale.sale:"
msgid "A customer invoice/refund from sale device has not been created."
msgstr ""
@ -84,10 +92,6 @@ msgctxt "error:sale.sale:"
msgid "You can not force to draft a invoice paid!"
msgstr "No puede forzar a borrador una factura pagada!"
msgctxt "error:sale_pos.force_draft:"
msgid "The electronic invoice already exist!"
msgstr "La factura electrónica ya existe!"
msgctxt "field:account.invoice,position:"
msgid "Position"
msgstr "Posición"
@ -116,6 +120,11 @@ msgctxt "field:account.statement,sale_device:"
msgid "Device"
msgstr "Terminal"
#, fuzzy
msgctxt "field:account.statement,salesman:"
msgid "Salesman"
msgstr "Vendedor"
msgctxt "field:account.statement,total_money:"
msgid "Total Money"
msgstr "Dinero Total"
@ -140,14 +149,32 @@ msgctxt "field:account.statement.journal,kind:"
msgid "Kind"
msgstr "Clase"
#, fuzzy
msgctxt "field:account.statement.journal,party:"
msgid "Party"
msgstr "Terceros"
msgctxt "field:account.statement.journal,payment_means_code:"
msgid "Payment Means Code"
msgstr "Código Clasificación Tipo de Pago"
msgctxt "field:account.statement.journal,require_party:"
msgid "Require Party"
msgstr ""
msgctxt "field:account.statement.journal,require_voucher:"
msgid "Require Voucher"
msgstr "Requiere Comprobante"
msgctxt "field:account.statement.line,extra_amount:"
msgid "Extra"
msgstr ""
#, fuzzy
msgctxt "field:account.statement.line,net_amount:"
msgid "Net Amount"
msgstr "Valor Neto"
msgctxt "field:account.statement.line,sale:"
msgid "Sale"
msgstr "Venta"
@ -400,6 +427,7 @@ msgctxt "field:sale.shop,company_party:"
msgid ""
msgstr ""
msgctxt "field:sale.shop,computer_authorization:"
msgid "Computer Authorization"
msgstr "Autorización por Computador"
@ -576,6 +604,10 @@ msgctxt "field:sale_pos.portfolio_payments.start,id:"
msgid "ID"
msgstr "ID"
msgctxt "field:sale_pos.portfolio_payments.start,salesman:"
msgid "Salesman"
msgstr "Vendedor"
msgctxt "field:sale_pos.portfolio_payments.start,start_date:"
msgid "Start Date"
msgstr "Inicio"
@ -742,6 +774,10 @@ msgctxt "model:ir.action,name:act_sale_form"
msgid "POS Sales"
msgstr "Venta Rápida"
msgctxt "model:ir.action,name:act_sale_generate_shipment"
msgid "Generate Shipment"
msgstr "Generar Envío"
msgctxt "model:ir.action,name:act_sale_statement_form"
msgid "Statements"
msgstr "Estados de Cuenta"

43
sale.py
View file

@ -22,7 +22,7 @@ __all__ = [
'WizardSalePayment', 'SaleIncomeDailyStart', 'SaleIncomeDaily',
'SaleIncomeDailyReport', 'DeleteSalesDraft', 'PortfolioPaymentsStart',
'PortfolioPayments', 'PortfolioPaymentsReport', 'SaleByKindStart',
'SaleByKind', 'SaleByKindReport',
'SaleByKind', 'SaleByKindReport', 'SaleGenerateShipment'
]
_ZERO = Decimal('0.00')
@ -529,6 +529,7 @@ class Sale(metaclass=PoolMeta):
@classmethod
def do_stock_moves(cls, sales):
for sale in sales:
if sale.shipment_state == "none":
sale.create_shipment('out')
sale.set_shipment_state()
@ -721,12 +722,13 @@ class Sale(metaclass=PoolMeta):
move = line.get_move(shipment_type)
if move:
moves[line.id] = move
print('pasa por shipment without', moves)
to_create = []
for m in moves:
moves[m].state = 'draft'
to_create.append(moves[m]._save_values)
print(to_create)
Move.create(to_create)
Move.do(self.moves)
self.set_shipment_state()
@ -1107,8 +1109,8 @@ class SaleForceDraft(Wizard):
if sale.id:
cursor.execute(*sale_table.update(
columns=[sale_table.state],
values=['draft'],
columns=[sale_table.state, sale_table.shipment_state, sale_table.invoice_state],
values=['draft', 'none', 'none'],
where=sale_table.id == sale.id)
)
# The stock moves must be delete
@ -2017,3 +2019,36 @@ class PortfolioPaymentsReport(Report):
report_context['company'] = data['company_name']
report_context['sum_amount'] = sum([obj['payment_amount'] for obj in voucher_lines])
return report_context
class SaleGenerateShipment(Wizard):
"""
Sale Generate Shipment
"""
__name__ = 'sale.sale.generate_shipment'
start_state = 'generate_shipment'
generate_shipment = StateTransition()
@classmethod
def __setup__(cls):
super(SaleGenerateShipment, cls).__setup__()
cls._error_messages.update({
'dont_shipment_generated': (
'You can not to generate shipment!'
),
})
def transition_generate_shipment(self):
Sale = Pool().get('sale.sale')
ids = Transaction().context['active_ids']
if ids:
sale = Sale(ids[0])
if sale.state in ('cancelled', 'done'):
self.raise_user_error('dont_shipment_generated')
if sale.total_amount_cache < 0 and sale.state == 'none':
sale.create_shipment('return')
sale.set_shipment_state()
elif sale.state == 'none':
sale.create_shipment('out')
sale.set_shipment_state()
return 'end'

View file

@ -82,6 +82,16 @@
</record>
<!-- Actions -->
<record model="ir.action.wizard" id="act_sale_generate_shipment">
<field name="name">Generate Shipment</field>
<field name="wiz_name">sale.sale.generate_shipment</field>
</record>
<record model="ir.action.keyword" id="action_sale_generate_shipment_keyword">
<field name="keyword">form_action</field>
<field name="model">sale.sale,-1</field>
<field name="action" ref="act_sale_generate_shipment"/>
</record>
<record model="ir.action.act_window" id="act_sale_form">
<field name="name">POS Sales</field>
<field name="res_model">sale.sale</field>