How to make the predicate spent(Passengers, Year, Sum)? - swish

1. Write the predicate spent(Passengers, Year, Sum)
to find the total cost of tickets for passengers from
of the list of Passengers in year Year.
trip(01, Kuiv, Odessa, 1500).
trip(02, Kuiv, Lviv, 700).
trip(03, Uzhorod, Krum, 6000).
trip(04, Vunohradiv, Odessa, 2540).
trip(05, Ternopil, Kuiv, 3800).
trip(06, Zaporizhya, Donetsk, 900).
trip(07, Lytsk, Mariupol, 7500).
ticket(01, Maha, 2021-12-26).
ticket(02, Burcho, 2021-05-21).
ticket(03, Chegil, 2021-06-18).
ticket(04, Dovhinka, 2022-12-05).
ticket(05, Voloshyn, 2022-07-14).
ticket(06, Kristian, 2022-03-17).
ticket(07, Bolehan, 2022-01-03).
trip(01, Kuiv, Odessa, 1500).
trip(02, Kuiv, Lviv, 700).
trip(03, Uzhorod, Krum, 6000).
trip(04, Vunohradiv, Odessa, 2540).
trip(05, Ternopil, Kuiv, 3800).
trip(06, Zaporizhya, Donetsk, 900).
trip(07, Lytsk, Mariupol, 7500).
ticket(01, Maha, 2021-12-26).
ticket(02, Burcho, 2021-05-21).
ticket(03, Chegil, 2021-06-18).
ticket(04, Dovhinka, 2022-12-05).
ticket(05, Voloshyn, 2022-07-14).
ticket(06, Kristian, 2022-03-17).
ticket(07, Bolehan, 2022-01-03).
sum_cash(Price) :-
spent(sum(A), trip(_, _, _, A), Price).
I wrote this code, but it is not enough to complete the task, please help.

Related

how to pass values from sale to invoice odoo?

I have created new one2many field like order lines in sale after other info tab. Also,I have created a new one2many field like invoice lines in invoice form after other info tab.
What i need to do is, I have to pass values from sale one2many field to invoice one2many field while clicking create invoice button.
I have tried inheriting _prepare_invoice and _prepare_invoice_line function in default. It does not work for other one2many field.
Could anyone please help me to do this!
If you are using Odoo14/Odoo13/Odoo12/Odoo11 then you need to override the sale.order method i.e _prepare_invoice.
Below is the example of Odoo14
#api.model
def _prepare_invoice(self):
"""
Prepare the dict of values to create the new invoice for a sales order. This method may be
overridden to implement custom invoice generation (making sure to call super() to establish
a clean extension chain).
"""
self.ensure_one()
journal = self.env['account.move'].with_context(default_move_type='out_invoice')._get_default_journal()
if not journal:
raise UserError(_('Please define an accounting sales journal for the company %s (%s).') % (self.company_id.name, self.company_id.id))
invoice_vals = {
'ref': self.client_order_ref or '',
'move_type': 'out_invoice',
'narration': self.note,
'currency_id': self.pricelist_id.currency_id.id,
'campaign_id': self.campaign_id.id,
'medium_id': self.medium_id.id,
'source_id': self.source_id.id,
'invoice_user_id': self.user_id and self.user_id.id,
'team_id': self.team_id.id,
'partner_id': self.partner_invoice_id.id,
'partner_shipping_id': self.partner_shipping_id.id,
'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id.get_fiscal_position(self.partner_invoice_id.id)).id,
'partner_bank_id': self.company_id.partner_id.bank_ids[:1].id,
'journal_id': journal.id, # company comes from the journal
'invoice_origin': self.name,
'invoice_payment_term_id': self.payment_term_id.id,
'payment_reference': self.reference,
'transaction_ids': [(6, 0, self.transaction_ids.ids)],
'invoice_line_ids': [],
'company_id': self.company_id.id,
'tax_line': [(6, 0, self.tax_line.ids)] //This is my customize field.
}
return invoice_vals
You can't directly pass the o2M which will be entirely different ids.
'account_tax_line_ids': [(6, 0, self.sale_tax_line_ids.ids)] is not possible.
If you need to edit account_tax_line_ids again in the invoice form and
sale_tax_line_ids value should not change, then try below.
#api.multi
def _prepare_invoice(self):
self.ensure_one()
invoice_vals = super(SaleOrder, self)._prepare_invoice()
invoice_vals['account_tax_line_ids'] = [(0, 0, {'FIELD1': line.FIELD1_VALUE, ... } for line in self.sale_tax_line_ids]
return invoice_vals
Specify the fields in side Dictionary.
Read your comments and find out why it's not shown or not getting errors.
In the sale order field:
sale_tax_line_ids = fields.One2many('**sale.order.tax**', 'sale_id', string='Tax Lines', readonly=True, states={'draft': [('readonly', False)]}, copy=True)
And, in the account, move:
account_tax_line_ids = fields.One2many('**account.tax.line**', 'account_line_id', string='Taxes') and you set value like 'account_tax_line_ids': [(6, 0,**self.sale_tax_line_ids.ids**)]
So in the account_tax_line_ids fields, you should set the account.tax.line model records, but you are trying to set sale.order.tax model records.
Also, you can see in the odoo default, like in the sale order line, there is product_id, so it is related to the product.product model, and same with account: move line there product_id, which relates to product.product model. So it sets sale order line product to account move line product.

Laravel Query. Obtain in Eloquent only totals > 0

I have this query:
public static function totalByAgent(int $agentId)
{
return PropertyListing::select(
DB::raw('SUM(property_listing.rental) as rental'),
DB::raw('SUM(property_listing.sale) as sale'),
'property_category.name as category_name',
'property_category.id as category_id'
)->join(
'property_category',
'property_category.id',
'property_listing.category_id'
)->where('agent_id', $agentId)->groupBy('property_category.id')->get();
}
With this query I obtain the sum of properties for sale and sum of properties to rent group by property categories. But If some property have only properties for sale and 0 to rent I obtain 0 in sum of rents.
I tried adding:
->having('sale', '>', 0)->get()
after groupBy. this hides the rents if they had.
Any idea?
Best regards
Finally this query works for me:
return Property::published()->select(DB::raw('SUM(property.rental) as rental'),
DB::raw('SUM(property.sale) as sale'),
'property_category.name as category_name',
'property_category.id as category_id')
->join('property_category', 'property_category.id', 'property.category_id')
->whereExists(function ($query) use ($agentId){
$query->select('property_listing.agent_id')
->from('property_listing')
->whereRaw('property.id = property_listing.property_id')
->where('property_listing.agent_id', $agentId);
})->published()
->groupBy('property_category.id')->get();

VueJS dependent properties

There is a form with 3 fields,
Total Item (QTY)
UNIT Price (Single Item)
Total Price (All Items)
The scenario is like this, user will enter Total Item along with one other value, either unit price or total price,
if user enter unit price, I have to calculate total price by multiplying total item into unit price,
if user enter total price, I have to divide it by total item and get the unit price.
I am trying to achieve it with including unit price and total price in watch without success, here is my code,
watch:{
unit_rate: function(newVal){
if(newVal != ''){
this.total_rate = parseInt(this.total_item) * parseFloat(newVal);
}else{
this.total_rate = '';
}
},
total_rate: function(newVal){
if(newVal != ''){
this.unit_rate = parseFloat(newVal) / parseInt(this.total_item);
}else{
this.unit_rate = '';
}
}
},
I am not sure whether I can modify the property like this while both of them are already in the observe. I did not get the expected output as well, something wrong,,

Netsuite Suitetalk: How to get all the customers whose account balance has changed

Customer lastModifiedDate is not updated if you create cash sale/invoice of particular customer in Netsuite. customer balance is changed but customer lastModifiedDate is not changing.
how can I get all those customers their balance is updated as per lastModifiedDate.
Please have a look at code below.
CustomerSearch customerSearch = new CustomerSearch();
CustomerSearchBasic customerBasic = new CustomerSearchBasic();
customerBasic.lastModifiedDate = new SearchDateField()
{
#operator = SearchDateFieldOperator.onOrAfter,
operatorSpecified = true,
searchValue = new DateTime(2018, 10, 20, 13, 50, 00, DateTimeKind.Utc),
searchValueSpecified = true,
};
customerSearch.basic = customerBasic;
SearchResult result = ACGApplication.Client.Service.search(customerSearch);
var customerList = result.recordList.Cast<com.netsuite.webservices.Customer>();
I think you can do this via a saved search that looks at dates of transactions that effect customer balance - invoices, cash sales, payments, credits, etc.
Group them by customer with a MAX summary function on the date. If you want “within the last week” or some other criteria, add the MAX summary to the criteria tab of the saved search.
Call the saved search via SuiteTalk.

How partial payment hit accounting statements in odoo 10 Using Point Of sale?

As I have purchased pos_partial_payment module but found incomplete for my requirement so need to modify/add new functionality to it. As I perform partial payment (remaining credit amount) there is not changes to accounting.
For example, such partial paid amount is not showing in accounting and also not changing account receivable to Cash journal.
#api.one
def pay_partial_payment(self, amount):
# Comment this method because we don't want generate payment accounting entry, if you want then just Uncomment it...
print "partnerrrrrrrrrrrrrrrrrrrrrrr id",self
print "****************codeeeeeeeeeeeeeeeeeeeeeeeee",amount
#finding recivble
print "id of account rec account",self.property_account_receivable_id.id
lines = []
partner_line = {'account_id':self.property_account_receivable_id.id,
'name':'/',
'date':date.today(),
'partner_id': self.id,
'debit':float(amount),
'credit':0.0,
}
lines.append(partner_line)
#find sale account
recivable_ids = self.env['account.account'].search([('user_type_id.name','=','Receivable')])
print "*********************************************************recivable_ids",recivable_ids
rec_id = False
if recivable_ids:
rec_id = recivable_ids[0]
pos_line = {'account_id':rec_id.id,
'name':'pos partial payment',
'date':date.today(),
'partner_id': self.id,
'credit':float(amount),
'debit':0.0,
}
lines.append(pos_line)
line_list = [(0, 0, x) for x in lines]
move_id = self.env['account.move'].create({'partner_id':self.id,
'date':date.today(),
# 'journal_id':7,
'journal_id':6,
'line_ids':line_list
})
return True